3232# without thread support.
3333import threading
3434
35- import multiprocessing .dummy
3635import multiprocessing .connection
37- import multiprocessing .managers
36+ import multiprocessing .dummy
3837import multiprocessing .heap
38+ import multiprocessing .managers
3939import multiprocessing .pool
40+ import multiprocessing .queues
4041
4142from multiprocessing import util
4243
6465def latin (s ):
6566 return s .encode ('latin' )
6667
68+
69+ def close_queue (queue ):
70+ if isinstance (queue , multiprocessing .queues .Queue ):
71+ queue .close ()
72+ queue .join_thread ()
73+
74+
6775#
6876# Constants
6977#
@@ -825,6 +833,7 @@ def test_qsize(self):
825833 self .assertEqual (q .qsize (), 1 )
826834 q .get ()
827835 self .assertEqual (q .qsize (), 0 )
836+ close_queue (q )
828837
829838 @classmethod
830839 def _test_task_done (cls , q ):
@@ -897,6 +906,7 @@ def __reduce__(self):
897906 q .put (True )
898907 # bpo-30595: use a timeout of 1 second for slow buildbots
899908 self .assertTrue (q .get (timeout = 1.0 ))
909+ close_queue (q )
900910
901911#
902912#
@@ -1020,10 +1030,12 @@ def test_notify(self):
10201030 p = self .Process (target = self .f , args = (cond , sleeping , woken ))
10211031 p .daemon = True
10221032 p .start ()
1033+ self .addCleanup (p .join )
10231034
10241035 p = threading .Thread (target = self .f , args = (cond , sleeping , woken ))
10251036 p .daemon = True
10261037 p .start ()
1038+ self .addCleanup (p .join )
10271039
10281040 # wait for both children to start sleeping
10291041 sleeping .acquire ()
@@ -1066,11 +1078,13 @@ def test_notify_all(self):
10661078 args = (cond , sleeping , woken , TIMEOUT1 ))
10671079 p .daemon = True
10681080 p .start ()
1081+ self .addCleanup (p .join )
10691082
10701083 t = threading .Thread (target = self .f ,
10711084 args = (cond , sleeping , woken , TIMEOUT1 ))
10721085 t .daemon = True
10731086 t .start ()
1087+ self .addCleanup (t .join )
10741088
10751089 # wait for them all to sleep
10761090 for i in range (6 ):
@@ -1089,10 +1103,12 @@ def test_notify_all(self):
10891103 p = self .Process (target = self .f , args = (cond , sleeping , woken ))
10901104 p .daemon = True
10911105 p .start ()
1106+ self .addCleanup (p .join )
10921107
10931108 t = threading .Thread (target = self .f , args = (cond , sleeping , woken ))
10941109 t .daemon = True
10951110 t .start ()
1111+ self .addCleanup (t .join )
10961112
10971113 # wait for them to all sleep
10981114 for i in range (6 ):
@@ -1123,10 +1139,12 @@ def test_notify_n(self):
11231139 p = self .Process (target = self .f , args = (cond , sleeping , woken ))
11241140 p .daemon = True
11251141 p .start ()
1142+ self .addCleanup (p .join )
11261143
11271144 t = threading .Thread (target = self .f , args = (cond , sleeping , woken ))
11281145 t .daemon = True
11291146 t .start ()
1147+ self .addCleanup (t .join )
11301148
11311149 # wait for them to all sleep
11321150 for i in range (6 ):
@@ -1309,6 +1327,7 @@ def test_event(self):
13091327 p .daemon = True
13101328 p .start ()
13111329 self .assertEqual (wait (), True )
1330+ p .join ()
13121331
13131332#
13141333# Tests for Barrier - adapted from tests in test/lock_tests.py
@@ -1654,6 +1673,7 @@ def test_thousand(self):
16541673 p = self .Process (target = self ._test_thousand_f ,
16551674 args = (self .barrier , passes , child_conn , lock ))
16561675 p .start ()
1676+ self .addCleanup (p .join )
16571677
16581678 for i in range (passes ):
16591679 for j in range (self .N ):
0 commit comments