summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/base_events.py
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-09-28 17:39:42 (GMT)
committerGitHub <noreply@github.com>2022-09-28 17:39:42 (GMT)
commit575a253b5c203e8d2ebfd239ed5a613179f8984f (patch)
tree2bf2c6833ef3d08ae73cf410bacf24703f1f9ae1 /Lib/asyncio/base_events.py
parent9a404b173e57ce171a867cfc3776cdf88d6c553f (diff)
downloadcpython-575a253b5c203e8d2ebfd239ed5a613179f8984f.zip
cpython-575a253b5c203e8d2ebfd239ed5a613179f8984f.tar.gz
cpython-575a253b5c203e8d2ebfd239ed5a613179f8984f.tar.bz2
GH-82448: Add thread timeout for loop.shutdown_default_executor (#97561)
Co-authored-by: Kyle Stanley <aeros167@gmail.com>
Diffstat (limited to 'Lib/asyncio/base_events.py')
-rw-r--r--Lib/asyncio/base_events.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index a675fff..9c9d98d 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -561,8 +561,13 @@ class BaseEventLoop(events.AbstractEventLoop):
'asyncgen': agen
})
- async def shutdown_default_executor(self):
- """Schedule the shutdown of the default executor."""
+ async def shutdown_default_executor(self, timeout=None):
+ """Schedule the shutdown of the default executor.
+
+ The timeout parameter specifies the amount of time the executor will
+ be given to finish joining. The default value is None, which means
+ that the executor will be given an unlimited amount of time.
+ """
self._executor_shutdown_called = True
if self._default_executor is None:
return
@@ -572,7 +577,13 @@ class BaseEventLoop(events.AbstractEventLoop):
try:
await future
finally:
- thread.join()
+ thread.join(timeout)
+
+ if thread.is_alive():
+ warnings.warn("The executor did not finishing joining "
+ f"its threads within {timeout} seconds.",
+ RuntimeWarning, stacklevel=2)
+ self._default_executor.shutdown(wait=False)
def _do_shutdown(self, future):
try: