aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/asyncio/runners.py
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-02-12 07:53:52 +0300
committershadchin <shadchin@yandex-team.com>2024-02-12 08:07:36 +0300
commitce1b7ca3171f9158180640c6a02a74b4afffedea (patch)
treee47c1e8391b1b0128262c1e9b1e6ed4c8fff2348 /contrib/tools/python3/src/Lib/asyncio/runners.py
parent57350d96f030db90f220ce50ee591d5c5d403df7 (diff)
downloadydb-ce1b7ca3171f9158180640c6a02a74b4afffedea.tar.gz
Update Python from 3.11.8 to 3.12.2
Diffstat (limited to 'contrib/tools/python3/src/Lib/asyncio/runners.py')
-rw-r--r--contrib/tools/python3/src/Lib/asyncio/runners.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/contrib/tools/python3/src/Lib/asyncio/runners.py b/contrib/tools/python3/src/Lib/asyncio/runners.py
index b3e0c44b7f..1b89236599 100644
--- a/contrib/tools/python3/src/Lib/asyncio/runners.py
+++ b/contrib/tools/python3/src/Lib/asyncio/runners.py
@@ -5,12 +5,11 @@ import enum
import functools
import threading
import signal
-import sys
from . import coroutines
from . import events
from . import exceptions
from . import tasks
-
+from . import constants
class _State(enum.Enum):
CREATED = "created"
@@ -70,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)
@@ -157,12 +157,12 @@ class Runner:
raise KeyboardInterrupt()
-def run(main, *, debug=None):
+def run(main, *, debug=None, loop_factory=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.
@@ -173,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():
@@ -186,7 +190,7 @@ def run(main, *, debug=None):
raise RuntimeError(
"asyncio.run() cannot be called from a running event loop")
- with Runner(debug=debug) as runner:
+ with Runner(debug=debug, loop_factory=loop_factory) as runner:
return runner.run(main)