Skip to content

Commit 02891f9

Browse files
committed
tidy
1 parent 75ac805 commit 02891f9

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

Lib/concurrent/futures/thread.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _python_exit():
3636
# See bpo-39812 for context.
3737
threading._register_atexit(_python_exit)
3838

39-
# Make sure `_global_shutdown_lock` is reinit in forked children
39+
# At fork, reinitialize the `_global_shutdown_lock` lock in the child process
4040
if hasattr(os, 'register_at_fork'):
4141
os.register_at_fork(before=_global_shutdown_lock.acquire,
4242
after_in_child=_global_shutdown_lock._at_fork_reinit,

Lib/test/test_concurrent_futures.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -568,19 +568,6 @@ def test_shutdown_no_wait(self):
568568
# shutdown.
569569
assert all([r == abs(v) for r, v in zip(res, range(-5, 5))])
570570

571-
def test_hang_issue45021(self):
572-
"""https://bugs.python.org/issue45021"""
573-
def submit(pool):
574-
pool.submit(submit, pool)
575-
576-
if hasattr(os, 'register_at_fork'):
577-
with futures.ThreadPoolExecutor(1) as pool:
578-
pool.submit(submit, pool)
579-
580-
for _ in range(50):
581-
with futures.ProcessPoolExecutor(1, mp_context=get_context('fork')) as workers:
582-
workers.submit(tuple)
583-
584571

585572
create_executor_tests(ProcessPoolShutdownTest,
586573
executor_mixins=(ProcessPoolForkMixin,
@@ -918,6 +905,20 @@ def test_idle_thread_reuse(self):
918905
self.assertEqual(len(executor._threads), 1)
919906
executor.shutdown(wait=True)
920907

908+
@unittest.skipUnless(hasattr(os, 'register_at_fork'), 'need os.register_at_fork')
909+
def test_hang_global_shutdown_lock(self):
910+
# bpo-45021: _global_shutdown_lock should be reinitialized in the child
911+
# process, otherwise it will never exit
912+
def submit(pool):
913+
pool.submit(submit, pool)
914+
915+
with futures.ThreadPoolExecutor(1) as pool:
916+
pool.submit(submit, pool)
917+
918+
for _ in range(50):
919+
with futures.ProcessPoolExecutor(1, mp_context=get_context('fork')) as workers:
920+
workers.submit(tuple)
921+
921922

922923
class ProcessPoolExecutorTest(ExecutorTest):
923924

0 commit comments

Comments
 (0)