diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-03-16 05:08:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-16 05:08:11 (GMT) |
commit | 97812403bf01f665b27d7506f209ac9f1e913f24 (patch) | |
tree | 89688d725932c0ac9cec0689c3962ae395d741f1 /Lib/test | |
parent | bef189b5c72a25a80d58c46f9e591a1b6db2187a (diff) | |
download | cpython-97812403bf01f665b27d7506f209ac9f1e913f24.zip cpython-97812403bf01f665b27d7506f209ac9f1e913f24.tar.gz cpython-97812403bf01f665b27d7506f209ac9f1e913f24.tar.bz2 |
gh-94440: Fix issue of ProcessPoolExecutor shutdown hanging (GH-94468)
Fix an issue of concurrent.futures ProcessPoolExecutor shutdown hanging.
(cherry picked from commit 2dc94634b50f0e5e207787e5ac1d56c68b22c3ae)
Co-authored-by: yonatanp <yonatan.perry@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_concurrent_futures.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py index e174d54..6eae8c9 100644 --- a/Lib/test/test_concurrent_futures.py +++ b/Lib/test/test_concurrent_futures.py @@ -14,6 +14,7 @@ import logging from logging.handlers import QueueHandler import os import queue +import signal import sys import threading import time @@ -397,6 +398,33 @@ class ExecutorShutdownTest: self.assertFalse(err) self.assertEqual(out.strip(), b"apple") + def test_hang_gh94440(self): + """shutdown(wait=True) doesn't hang when a future was submitted and + quickly canceled right before shutdown. + + See https://github.com/python/cpython/issues/94440. + """ + if not hasattr(signal, 'alarm'): + raise unittest.SkipTest( + "Tested platform does not support the alarm signal") + + def timeout(_signum, _frame): + raise RuntimeError("timed out waiting for shutdown") + + kwargs = {} + if getattr(self, 'ctx', None): + kwargs['mp_context'] = self.get_context() + executor = self.executor_type(max_workers=1, **kwargs) + executor.submit(int).result() + old_handler = signal.signal(signal.SIGALRM, timeout) + try: + signal.alarm(5) + executor.submit(int).cancel() + executor.shutdown(wait=True) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old_handler) + class ThreadPoolShutdownTest(ThreadPoolMixin, ExecutorShutdownTest, BaseTestCase): def test_threads_terminate(self): |