summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-07-15 21:09:13 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-07-15 21:09:13 (GMT)
commit075050f84f15fb0681254dc3a0b7a53e9fe6668f (patch)
tree93294ba43d5efa613d422e83afd7da764740ddc2 /Lib/test
parentf26ad7149f91db1baf2dff38c9ad7a4f6f035036 (diff)
downloadcpython-075050f84f15fb0681254dc3a0b7a53e9fe6668f.zip
cpython-075050f84f15fb0681254dc3a0b7a53e9fe6668f.tar.gz
cpython-075050f84f15fb0681254dc3a0b7a53e9fe6668f.tar.bz2
test_threaded_import must clean up after itself
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_threaded_import.py11
-rw-r--r--Lib/test/threaded_import_hangers.py14
2 files changed, 16 insertions, 9 deletions
diff --git a/Lib/test/test_threaded_import.py b/Lib/test/test_threaded_import.py
index 6919d21..789920b 100644
--- a/Lib/test/test_threaded_import.py
+++ b/Lib/test/test_threaded_import.py
@@ -11,8 +11,8 @@ import sys
import time
import shutil
import unittest
-from test.support import verbose, import_module, run_unittest, TESTFN
-thread = import_module('_thread')
+from test.support import (
+ verbose, import_module, run_unittest, TESTFN, reap_threads)
threading = import_module('threading')
def task(N, done, done_tasks, errors):
@@ -62,7 +62,7 @@ class Finder:
def __init__(self):
self.numcalls = 0
self.x = 0
- self.lock = thread.allocate_lock()
+ self.lock = threading.Lock()
def find_module(self, name, path=None):
# Simulate some thread-unsafe behaviour. If calls to find_module()
@@ -113,7 +113,9 @@ class ThreadedImportTests(unittest.TestCase):
done_tasks = []
done.clear()
for i in range(N):
- thread.start_new_thread(task, (N, done, done_tasks, errors,))
+ t = threading.Thread(target=task,
+ args=(N, done, done_tasks, errors,))
+ t.start()
done.wait(60)
self.assertFalse(errors)
if verbose:
@@ -203,6 +205,7 @@ class ThreadedImportTests(unittest.TestCase):
self.assertEqual(set(results), {'a', 'b'})
+@reap_threads
def test_main():
run_unittest(ThreadedImportTests)
diff --git a/Lib/test/threaded_import_hangers.py b/Lib/test/threaded_import_hangers.py
index adf03e3..d7cc255 100644
--- a/Lib/test/threaded_import_hangers.py
+++ b/Lib/test/threaded_import_hangers.py
@@ -35,8 +35,12 @@ for name, func, args in [
("os.path.abspath", os.path.abspath, ('.',)),
]:
- t = Worker(func, args)
- t.start()
- t.join(TIMEOUT)
- if t.is_alive():
- errors.append("%s appeared to hang" % name)
+ try:
+ t = Worker(func, args)
+ t.start()
+ t.join(TIMEOUT)
+ if t.is_alive():
+ errors.append("%s appeared to hang" % name)
+ finally:
+ del t
+