import thread import re import time import random import sys, traceback, pdb exc = None REPEATS = 2 THREADS = 10 LENGTH = 2 REGEX = re.compile('((?:foo|bar)+)(\d*)E?') def short_print(s): if len(s) > 25: print s[:20] + " ..." else: print s def parse(line, i): global exc, match try: m = REGEX.search(line) if m.groups(): short_print(m.group(1)) except: exc = sys.exc_info() def make(): foobar = [random.choice(('foo', 'bar')) for i in range(LENGTH)] n = random.randint(1, 99999) e = random.choice(('', 'E')) return "%s%d%s" % (''.join(foobar), n, e) # Make up material tests = [make() for i in range(THREADS)] #for test in tests[:5]: short_print(test) #time.sleep(5) print>>sys.stderr, "REPEATS=%d, THREADS=%d, LENGTH=%d." % (REPEATS, THREADS, LENGTH) start = thread.start_new_thread for i in xrange(REPEATS): for test in tests: start(parse, (test, i)) time.sleep(0.1) if exc is not None: break time.sleep(1) if exc is not None: print " *** Caught one! ***" e, v, t = exc traceback.print_exception(e, v, t, 10, sys.stderr) pdb.post_mortem(t) exit(1)