9
9
from . import events
10
10
from . import exceptions
11
11
from . import tasks
12
-
12
+ from . import constants
13
13
14
14
class _State (enum .Enum ):
15
15
CREATED = "created"
@@ -69,7 +69,8 @@ def close(self):
69
69
loop = self ._loop
70
70
_cancel_all_tasks (loop )
71
71
loop .run_until_complete (loop .shutdown_asyncgens ())
72
- loop .run_until_complete (loop .shutdown_default_executor ())
72
+ loop .run_until_complete (
73
+ loop .shutdown_default_executor (constants .THREAD_JOIN_TIMEOUT ))
73
74
finally :
74
75
if self ._set_event_loop :
75
76
events .set_event_loop (None )
@@ -160,8 +161,8 @@ def run(main, *, debug=None):
160
161
"""Execute the coroutine and return the result.
161
162
162
163
This function runs the passed coroutine, taking care of
163
- managing the asyncio event loop and finalizing asynchronous
164
- generators.
164
+ managing the asyncio event loop, finalizing asynchronous
165
+ generators and closing the default executor .
165
166
166
167
This function cannot be called when another asyncio event loop is
167
168
running in the same thread.
@@ -172,6 +173,10 @@ def run(main, *, debug=None):
172
173
It should be used as a main entry point for asyncio programs, and should
173
174
ideally only be called once.
174
175
176
+ The executor is given a timeout duration of 5 minutes to shutdown.
177
+ If the executor hasn't finished within that duration, a warning is
178
+ emitted and the executor is closed.
179
+
175
180
Example:
176
181
177
182
async def main():
0 commit comments