Conversation
PeriodicExecutor now falls back to a non-daemon thread when daemon threads are disallowed (subinterpreters). The monitor shutdown handler is also registered with threading._register_atexit so executors are stopped and joined before interpreter teardown. Adds regression tests for PeriodicExecutor in a real subinterpreter and for concurrent MongoClients across subinterpreters (Python 3.14+).
Runs live MongoClients inside interpreters managed by the standard InterpreterPoolExecutor, mirroring the existing multi-threaded checks. The pool's interpreters do not allow daemon threads, so this exercises the non-daemon monitor thread fallback and its shutdown handling.
The worker interpreters may not have the repo root on sys.path (the stdlib test package shadows the repo's), so the pickled worker function failed to unpickle. Submit the builtin exec with a code string that inserts the main interpreter's sys.path before importing pymongo.
Runs live AsyncMongoClients inside interpreters managed by InterpreterPoolExecutor. The async client runs its background tasks on the interpreter's own event loop rather than in threads, covering the other shutdown path.
Invert the is_running guard in test_subinterpreters: closing an idle interpreter runs threading._shutdown, which stops and joins pymongo's monitor threads, so the successful path must close them. Note in the changelog that both clients are covered by the subinterpreter tests.
Only register the monitor shutdown handler with threading._register_atexit when the interpreter disallows daemon threads, preserving normal main interpreter shutdown ordering.
blink1073
commented
Sep 21, 2026
blink1073
commented
Sep 21, 2026
blink1073
commented
Sep 21, 2026
blink1073
commented
Sep 21, 2026
blink1073
commented
Sep 21, 2026
blink1073
commented
Sep 21, 2026
Test AsyncPeriodicExecutor in a subinterpreter in the async suite, tighten the code comments, and note that both clients are supported in the changelog.
blink1073
commented
Sep 21, 2026
Add test/asynchronous/test_subinterpreters.py with the subinterpreter and InterpreterPoolExecutor client tests, written once in async style and mirrored by synchro. Remove them from test_threads.py, which is not mirrored. Collapse the periodic executor test's duplicated worker blocks into one block and make its async target a coroutine.
Commit 623ecb0 tightened the comment in the async monitor but did not regenerate the sync mirror.
…preter The sync worker blocks on an event set by the target's first run, so the interpreter is destroyed with the monitor live in its interval loop. The async worker yields to its loop once, which runs the monitor task's first step.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PYTHON-5418
Changes in this PR
PeriodicExecutorstarts non-daemon threads in subinterpreters, where daemon threads are disallowed. The monitor shutdown handler is registered withthreading._register_atexit(only in those interpreters) so executors are stopped and joined at interpreter teardown; main-interpreter shutdown ordering is unchanged.PeriodicExecutorin a subinterpreter and a dedicatedtest_subinterpreters.pycovering direct subinterpeter andInterpreterPoolExecutorusage with sync and aync clients.Test Plan
test_subinterpretersfails, demonstrating regression coverage.Checklist
Checklist for Author
Checklist for Reviewer