diff --git a/Lib/concurrent/futures/thread.py b/Lib/concurrent/futures/thread.py index 2af31a106d..889d1b328f 100644 --- a/Lib/concurrent/futures/thread.py +++ b/Lib/concurrent/futures/thread.py @@ -12,6 +12,7 @@ import queue import threading import weakref import os +import time # Workers are created as daemon threads. This is done to allow the interpreter # to exit when there are still idle threads in a ThreadPoolExecutor's thread @@ -32,8 +33,11 @@ _shutdown = False def _python_exit(): global _shutdown + print('Setting _shutdown') _shutdown = True items = list(_threads_queues.items()) + print('💀 Killing %d workers 💀' % len(items)) + time.sleep(2) for t, q in items: q.put(None) for t, q in items: @@ -167,6 +171,7 @@ class ThreadPoolExecutor(_base.Executor): if _shutdown: raise RuntimeError('cannot schedule new futures after ' 'interpreter shutdown') + time.sleep(2) f = _base.Future() w = _WorkItem(f, fn, args, kwargs) @@ -188,6 +193,7 @@ class ThreadPoolExecutor(_base.Executor): if num_threads < self._max_workers: thread_name = '%s_%d' % (self._thread_name_prefix or self, num_threads) + print('👶 Creating new thread: ', thread_name) t = threading.Thread(name=thread_name, target=_worker, args=(weakref.ref(self, weakref_cb), self._work_queue,