-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a bug where bootstrap code wasn't called (#1894)
- Loading branch information
1 parent
f2673b9
commit db402e8
Showing
3 changed files
with
32 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from asyncio import BaseEventLoop | ||
from multiprocessing import set_start_method | ||
from typing import Any | ||
|
||
|
||
async def _shutdown_default_executor( | ||
loop: BaseEventLoop, *args: Any, **kwargs: Any | ||
) -> None: | ||
try: | ||
await _original_shutdown_default_executor(loop, *args, **kwargs) | ||
except RuntimeError as error: | ||
# Work around a bug in Python 3.12 that will randomly cause a RuntimeError with the | ||
# following message to be raised. | ||
if "can't create new thread at interpreter shutdown" not in str(error): | ||
raise | ||
|
||
|
||
_bootstrapped = False | ||
|
||
|
||
if not _bootstrapped: | ||
_bootstrapped = True | ||
|
||
_original_shutdown_default_executor = BaseEventLoop.shutdown_default_executor | ||
BaseEventLoop.shutdown_default_executor = _shutdown_default_executor # type: ignore[assignment, callable-functiontype, method-assign, misc] | ||
|
||
# Avoid `fork` so as not to start worker processes with unneeded resources. | ||
# Use `spawn`, which is the Python 3.14 default. | ||
set_start_method("spawn", force=True) |
This file was deleted.
Oops, something went wrong.