@@ -11,7 +11,8 @@ |
|
|
11 |
11 |
|
12 |
12 |
import os, sys, time, unittest |
13 |
13 |
import test.support as support |
14 |
|
-_thread = support.import_module('_thread') |
|
14 |
+ |
|
15 |
+threading = support.import_module('threading') |
15 |
16 |
|
16 |
17 |
LONGSLEEP = 2 |
17 |
18 |
SHORTSLEEP = 0.5 |
@@ -20,8 +21,19 @@ |
|
|
20 |
21 |
class ForkWait(unittest.TestCase): |
21 |
22 |
|
22 |
23 |
def setUp(self): |
|
24 |
+self._threading_key = support.threading_setup() |
23 |
25 |
self.alive = {} |
24 |
26 |
self.stop = 0 |
|
27 |
+self.threads = [] |
|
28 |
+ |
|
29 |
+def tearDown(self): |
|
30 |
+# Stop threads |
|
31 |
+self.stop = 1 |
|
32 |
+for thread in self.threads: |
|
33 |
+thread.join() |
|
34 |
+thread = None |
|
35 |
+self.threads.clear() |
|
36 |
+support.threading_cleanup(*self._threading_key) |
25 |
37 |
|
26 |
38 |
def f(self, id): |
27 |
39 |
while not self.stop: |
@@ -43,10 +55,11 @@ def wait_impl(self, cpid): |
|
|
43 |
55 |
self.assertEqual(spid, cpid) |
44 |
56 |
self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) |
45 |
57 |
|
46 |
|
-@support.reap_threads |
47 |
58 |
def test_wait(self): |
48 |
59 |
for i in range(NUM_THREADS): |
49 |
|
-_thread.start_new(self.f, (i,)) |
|
60 |
+thread = threading.Thread(target=self.f, args=(i,)) |
|
61 |
+thread.start() |
|
62 |
+self.threads.append(thread) |
50 |
63 |
|
51 |
64 |
# busy-loop to wait for threads |
52 |
65 |
deadline = time.monotonic() + 10.0 |
@@ -75,8 +88,4 @@ def test_wait(self): |
|
|
75 |
88 |
os._exit(n) |
76 |
89 |
else: |
77 |
90 |
# Parent |
78 |
|
-try: |
79 |
|
-self.wait_impl(cpid) |
80 |
|
-finally: |
81 |
|
-# Tell threads to die |
82 |
|
-self.stop = 1 |
|
91 |
+self.wait_impl(cpid) |