import sys
import signal
import itertools
+import threading
from _weakrefset import WeakSet
#
sys.stderr.write('Process %s:\n' % self.name)
traceback.print_exc()
finally:
+ threading._shutdown()
util.info('process exiting with exitcode %d' % exitcode)
sys.stdout.flush()
sys.stderr.flush()
p.join()
close_queue(q)
+ @classmethod
+ def _test_wait_for_threads(self, evt):
+ def func1():
+ time.sleep(0.5)
+ evt.set()
+
+ def func2():
+ time.sleep(20)
+ evt.clear()
+
+ threading.Thread(target=func1).start()
+ threading.Thread(target=func2, daemon=True).start()
+
+ def test_wait_for_threads(self):
+ # A child process should wait for non-daemonic threads to end
+ # before exiting
+ if self.TYPE == 'threads':
+ self.skipTest('test not appropriate for {}'.format(self.TYPE))
+
+ evt = self.Event()
+ proc = self.Process(target=self._test_wait_for_threads, args=(evt,))
+ proc.start()
+ proc.join()
+ self.assertTrue(evt.is_set())
+
+
#
#
#
# the main thread's tstate_lock - that won't happen until the interpreter
# is nearly dead. So we release it here. Note that just calling _stop()
# isn't enough: other threads may already be waiting on _tstate_lock.
+ if _main_thread._is_stopped:
+ # _shutdown() was already called
+ return
tlock = _main_thread._tstate_lock
# The main thread isn't finished yet, so its thread state lock can't have
# been released.