You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(python): hand PyRuntime drop to shutdown_background inside a tokio context
Addresses review feedback on the ctx.fs PR after #2009 (deterministic
teardown) landed and changed PyRuntime::drop underneath it.
#2009's PyRuntime::drop does a blocking runtime join (join_without_gil)
while the interpreter is alive. The ctx.fs adapters now hold PyRuntime
clones, so when a Bash is dropped while `await execute()` is in flight,
the in-flight future drops the last Arc<Mutex<Bash>> — and thus the last
PyRuntime clone — on a pyo3-async-runtimes worker thread. A blocking
runtime drop inside a tokio context panics ("Cannot drop a runtime in a
context where blocking is not allowed"), surfacing as RustPanic to the
awaiting caller. Neither suite caught it because the merge stays green.
- PyRuntime::drop: also use shutdown_background() when
Handle::try_current().is_ok(), keeping #2009's deterministic
join_without_gil only on the normal Python-thread path.
- Regression test: drop a Bash while an async-callback execute() is in
flight, then await it (test_teardown_determinism.py). Verified it
panics without the fix and passes with it.
- Document and cover the third with_fs dispatch path: a Static handle
used from a thread with no tokio context (async callbacks under
execute_sync's private loop / await execute's caller loop) falls
through to self.rt.block_on. Adds execute_sync + async-callback +
ctx.fs tests (test_jupyter_compat.py).
- Docs: note that a stashed ctx.fs handle outlives the Bash and keeps
the VFS + runtime alive (specs + .pyi), and the in-tokio-context drop
handoff in the teardown-determinism section.
0 commit comments