summaryrefslogtreecommitdiff
path: root/Lib/test/test_threaded_import.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-02-16 07:26:27 +0000
committerTim Peters <tim.peters@gmail.com>2002-02-16 07:26:27 +0000
commitbaa2f7488fdc0bf558733f696d1d9aac7aa7aa5b (patch)
tree5d2b8b99fabcc02738eeef8e426eba0d595abc99 /Lib/test/test_threaded_import.py
parent139e3422b56843355fc9b70dd6d10bbd1f3ea77c (diff)
downloadcpython-baa2f7488fdc0bf558733f696d1d9aac7aa7aa5b.tar.gz
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.
Diffstat (limited to 'Lib/test/test_threaded_import.py')
-rw-r--r--Lib/test/test_threaded_import.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/test/test_threaded_import.py b/Lib/test/test_threaded_import.py
index e022c5fe92..d9f3d70573 100644
--- a/Lib/test/test_threaded_import.py
+++ b/Lib/test/test_threaded_import.py
@@ -17,9 +17,13 @@ def task():
x = random.randrange(1, 3)
critical_section.acquire()
N -= 1
- if N == 0:
- done.release()
+ # Must release critical_section before releasing done, else the main
+ # 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()
+ if finished:
+ done.release()
# 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.