mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
[3.12] gh-111358: Fix timeout behaviour in BaseEventLoop.shutdown_default_executor (GH-115622) (#115641)
(cherry picked from commit 53d5e67804
)
Co-authored-by: Jamie Phan <jamie@ordinarylab.dev>
This commit is contained in:
parent
ae6c01d9d2
commit
e25ac3ba1d
3 changed files with 29 additions and 9 deletions
|
@ -45,6 +45,7 @@ from . import protocols
|
|||
from . import sslproto
|
||||
from . import staggered
|
||||
from . import tasks
|
||||
from . import timeouts
|
||||
from . import transports
|
||||
from . import trsock
|
||||
from .log import logger
|
||||
|
@ -596,23 +597,24 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
thread = threading.Thread(target=self._do_shutdown, args=(future,))
|
||||
thread.start()
|
||||
try:
|
||||
await future
|
||||
finally:
|
||||
thread.join(timeout)
|
||||
|
||||
if thread.is_alive():
|
||||
async with timeouts.timeout(timeout):
|
||||
await future
|
||||
except TimeoutError:
|
||||
warnings.warn("The executor did not finishing joining "
|
||||
f"its threads within {timeout} seconds.",
|
||||
RuntimeWarning, stacklevel=2)
|
||||
f"its threads within {timeout} seconds.",
|
||||
RuntimeWarning, stacklevel=2)
|
||||
self._default_executor.shutdown(wait=False)
|
||||
else:
|
||||
thread.join()
|
||||
|
||||
def _do_shutdown(self, future):
|
||||
try:
|
||||
self._default_executor.shutdown(wait=True)
|
||||
if not self.is_closed():
|
||||
self.call_soon_threadsafe(future.set_result, None)
|
||||
self.call_soon_threadsafe(futures._set_result_unless_cancelled,
|
||||
future, None)
|
||||
except Exception as ex:
|
||||
if not self.is_closed():
|
||||
if not self.is_closed() and not future.cancelled():
|
||||
self.call_soon_threadsafe(future.set_exception, ex)
|
||||
|
||||
def _check_running(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue