Skip to content

Commit abc03ec

Browse files
congzhangzhclaude
andcommitted
gh-145342: Make the guest I/O thread non-daemonic with graceful shutdown
Address review feedback on the guest-mode runtime: - The I/O thread is no longer a daemon thread; it is joined when the run finishes, and a threading._register_atexit() hook (the concurrent.futures pattern) wakes it out of its selector wait so an unfinished run cannot hang interpreter shutdown. - Reuse loop._run_forever_setup()/_run_forever_cleanup() so the whole guest run counts as running: get_running_loop() works, is_running() is true, nested run_forever()/run_until_complete() raise, asyncgen hooks and coroutine origin tracking are installed and restored. On Windows this also establishes the proactor self-reading loop needed for call_soon_threadsafe() to wake IocpProactor.select(). - Preserve the host's signal wakeup fd across loop creation and close (the proactor installs/resets it in __init__/close on the main thread). - On completion, run the same cleanup as asyncio.run() -- cancel remaining tasks, shutdown asyncgens and the default executor, close the loop -- before invoking done_callback. - Harden the host/IO-thread handshake: exception-safe token handoff, and an abort path that unwinds the main task if the I/O thread dies. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent e6d30f8 commit abc03ec

1 file changed

Lines changed: 304 additions & 76 deletions

File tree

0 commit comments

Comments
 (0)