-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a workaround for a bug in Python 3.12 that would randomly cause R…
…untimeError to be raised when cleaning up thread pools during interpreter shutdown. (#1231)
- Loading branch information
1 parent
9dac6c5
commit e978045
Showing
2 changed files
with
18 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
"""The Betty package root.""" | ||
from pathlib import Path | ||
|
||
from betty import _patch # noqa: F401 | ||
|
||
|
||
# This lives here so it can be imported before any third-party Python modules are available. | ||
_ROOT_DIRECTORY_PATH = Path(__file__).resolve().parents[1] |
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,15 @@ | ||
from asyncio import BaseEventLoop | ||
from typing import Any | ||
|
||
_original_shutdown_default_executor = BaseEventLoop.shutdown_default_executor | ||
|
||
|
||
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 | ||
BaseEventLoop.shutdown_default_executor = _shutdown_default_executor # type: ignore[assignment, method-assign] |