Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PYTHON-4147: Silence noisy thread.start() RuntimeError at shutdown #1486

Merged
merged 10 commits into from
Feb 5, 2024
9 changes: 8 additions & 1 deletion pymongo/periodic_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,14 @@ def open(self) -> None:
thread.daemon = True
self._thread = weakref.proxy(thread)
_register_executor(self)
thread.start()
try:
ShaneHarvey marked this conversation as resolved.
Show resolved Hide resolved
thread.start()
except RuntimeError as e:
if str(e) == "can't create new thread at interpreter shutdown":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're assuming this error message will remain constant, right?

Copy link
Contributor Author

@Jibola Jibola Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Worst case, we can also directly tie this check to version 3.12 if it becomes something that does change. Waiting on response to python/cpython#114570 and follow up based on that.

# Result of change
Jibola marked this conversation as resolved.
Show resolved Hide resolved
self._thread = None
return
raise

def close(self, dummy: Any = None) -> None:
"""Stop. To restart, call open().
Expand Down
Loading