File tree 1 file changed +17
-6
lines changed 1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change 13
13
"""
14
14
15
15
import os , sys , time , unittest
16
- import test .test_support as test_support
17
- thread = test_support .import_module ('thread' )
16
+ import test .support as support
17
+
18
+ threading = support .import_module ('threading' )
18
19
19
20
LONGSLEEP = 2
20
21
SHORTSLEEP = 0.5
23
24
class ForkWait (unittest .TestCase ):
24
25
25
26
def setUp (self ):
27
+ self ._threading_key = support .threading_setup ()
26
28
self .alive = {}
27
29
self .stop = 0
30
+ self .threads = []
31
+
32
+ def tearDown (self ):
33
+ # Stop threads
34
+ self .stop = 1
35
+ for thread in self .threads :
36
+ thread .join ()
37
+ thread = None
38
+ del self .threads [:]
39
+ support .threading_cleanup (* self ._threading_key )
28
40
29
41
def f (self , id ):
30
42
while not self .stop :
@@ -48,7 +60,9 @@ def wait_impl(self, cpid):
48
60
49
61
def test_wait (self ):
50
62
for i in range (NUM_THREADS ):
51
- thread .start_new (self .f , (i ,))
63
+ thread = threading .Thread (target = self .f , args = (i ,))
64
+ thread .start ()
65
+ self .threads .append (thread )
52
66
53
67
time .sleep (LONGSLEEP )
54
68
@@ -74,6 +88,3 @@ def test_wait(self):
74
88
else :
75
89
# Parent
76
90
self .wait_impl (cpid )
77
- # Tell threads to die
78
- self .stop = 1
79
- time .sleep (2 * SHORTSLEEP ) # Wait for threads to die
You can’t perform that action at this time.
0 commit comments