Skip to content

Commit 0f88427

Browse files
committed
Issue python#15101: Make pool finalizer avoid joining current thread.
2 parents 1375884 + f29ec4b commit 0f88427

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

Lib/multiprocessing/pool.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ def _terminate_pool(cls, taskqueue, inqueue, outqueue, pool,
496496
# We must wait for the worker handler to exit before terminating
497497
# workers because we don't want workers to be restarted behind our back.
498498
debug('joining worker handler')
499-
worker_handler.join()
499+
if threading.current_thread() is not worker_handler:
500+
worker_handler.join()
500501

501502
# Terminate workers which haven't already finished.
502503
if pool and hasattr(pool[0], 'terminate'):
@@ -506,10 +507,12 @@ def _terminate_pool(cls, taskqueue, inqueue, outqueue, pool,
506507
p.terminate()
507508

508509
debug('joining task handler')
509-
task_handler.join()
510+
if threading.current_thread() is not task_handler:
511+
task_handler.join()
510512

511513
debug('joining result handler')
512-
result_handler.join()
514+
if threading.current_thread() is not result_handler:
515+
result_handler.join()
513516

514517
if pool and hasattr(pool[0], 'terminate'):
515518
debug('joining pool workers')

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Core and Builtins
2929
Library
3030
-------
3131

32+
- Issue #15101: Make pool finalizer avoid joining current thread.
33+
3234
- Issue #14657: The frozen instance of importlib used for bootstrap is now
3335
also the module imported as importlib._bootstrap.
3436

0 commit comments

Comments
 (0)