Skip to content
Discussion options

You must be logged in to vote

Confirmed, in-process there's still nothing besides PyThreadState_SetAsyncExc (pyo3 exposes it as pyo3::ffi::PyThreadState_SetAsyncExc). CPython has no API to force-kill a thread, so that part hasn't changed.

Two gotchas before you lean on it. It injects a normal, catchable exception at Python bytecode boundaries, so (a) a script stuck in a blocking C call (time.sleep, blocking IO, a C extension) isn't interrupted until that call returns, and (b) even a pure-Python loop survives if it's wrapped in a broad except:. On 3.9 an unguarded busy loop dies right after injection, but a time.sleep(30) thread and an except-guarded loop both stay alive even after SetAsyncExc returns 1. It also keys o…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@LangArthur
Comment options

Answer selected by LangArthur
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants