Commit 20882dd1 authored by Tim Peters's avatar Tim Peters

SF bug #516372: test_thread: unhandled exc. in thread

Fix exit races in test_thread.py and test_threaded_import.py.
I suspect the bug is provokable only under Linux (where child threads
seem to get lots of cycles before they get killed after the main thread
exits), or on multi-processor machines running other OSes.
Bugfix candidate.
parent e73ad2a2
...@@ -97,10 +97,14 @@ def task2(ident): ...@@ -97,10 +97,14 @@ def task2(ident):
if verbose: if verbose:
print 'task', ident, 'leaving barrier', i print 'task', ident, 'leaving barrier', i
mutex.acquire() mutex.acquire()
running = running - 1 running -= 1
if running == 0: # Must release mutex before releasing done, else the main thread can
done.release() # exit and set mutex to None as part of global teardown; then
# mutex.release() raises AttributeError.
finished = running == 0
mutex.release() mutex.release()
if finished:
done.release()
print '\n*** Barrier Test ***' print '\n*** Barrier Test ***'
if done.acquire(0): if done.acquire(0):
......
...@@ -17,9 +17,13 @@ def task(): ...@@ -17,9 +17,13 @@ def task():
x = random.randrange(1, 3) x = random.randrange(1, 3)
critical_section.acquire() critical_section.acquire()
N -= 1 N -= 1
if N == 0: # Must release critical_section before releasing done, else the main
done.release() # thread can exit and set critical_section to None as part of global
# teardown; then critical_section.release() raises AttributeError.
finished = N == 0
critical_section.release() critical_section.release()
if finished:
done.release()
# Tricky: When regrtest imports this module, the thread running regrtest # Tricky: When regrtest imports this module, the thread running regrtest
# grabs the import lock and won't let go of it until this module returns. # grabs the import lock and won't let go of it until this module returns.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment