GH-82448: Add thread timeout for loop.shutdown_default_executor (#97561)

Co-authored-by: Kyle Stanley <aeros167@gmail.com>
This commit is contained in:
Kumar Aditya 2022-09-28 23:09:42 +05:30 committed by GitHub
parent 9a404b173e
commit 575a253b5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 9 deletions

View file

@ -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: