summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/runners.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/runners.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/runners.py')
-rw-r--r--Lib/asyncio/runners.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/asyncio/runners.py b/Lib/asyncio/runners.py
index 840b133..b1c4dbd 100644
--- a/Lib/asyncio/runners.py
+++ b/Lib/asyncio/runners.py
@@ -9,7 +9,7 @@ from . import coroutines
from . import events
from . import exceptions
from . import tasks
-
+from . import constants
class _State(enum.Enum):
CREATED = "created"
@@ -69,7 +69,8 @@ class Runner:
loop = self._loop
_cancel_all_tasks(loop)
loop.run_until_complete(loop.shutdown_asyncgens())
- loop.run_until_complete(loop.shutdown_default_executor())
+ loop.run_until_complete(
+ loop.shutdown_default_executor(constants.THREAD_JOIN_TIMEOUT))
finally:
if self._set_event_loop:
events.set_event_loop(None)
@@ -160,8 +161,8 @@ def run(main, *, debug=None):
"""Execute the coroutine and return the result.
This function runs the passed coroutine, taking care of
- managing the asyncio event loop and finalizing asynchronous
- generators.
+ managing the asyncio event loop, finalizing asynchronous
+ generators and closing the default executor.
This function cannot be called when another asyncio event loop is
running in the same thread.
@@ -172,6 +173,10 @@ def run(main, *, debug=None):
It should be used as a main entry point for asyncio programs, and should
ideally only be called once.
+ The executor is given a timeout duration of 5 minutes to shutdown.
+ If the executor hasn't finished within that duration, a warning is
+ emitted and the executor is closed.
+
Example:
async def main():