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
{{ message }}
Repository navigation
Give PyErr_CheckSignals guide-level documentation #134075
Compiled extensions that "want to be interruptible by user requests" need to call PyErr_CheckSignals periodically; when it returns -1, they should stop work, clean up after themselves, and return to the interpreter.
This function is not mentioned at all in the extending and embedding guide, and its reference documentation makes it sound unimportant. As a result, many extension authors are (it seems to me) not aware that it exists or that they ought to be calling it, and so many extensions that should be interruptible by user requests aren't. For example, if you execute this code
>>> import numpy as np
>>> rng = np.random.default_rng()
>>> x = rng.random(1000000000)
and then immediately hit control-C, you'll be waiting at least a few seconds before you get the prompt back.
PyErr_CheckSignals also has the unusual property of potentially executing arbitrary Python code before returning to its caller, which makes it easy to use unsafely. Making an extension interruptible throughout may necessitate calling PyErr_CheckSignals from innermost loops where one would ideally release the GIL, which makes that worse (see #133465).
Thus, I suggest that a guide to correct use of PyErr_CheckSignals should be added to the extending and embedding guide.
@AA-Turner Sorry, no, I wrote the slide deck directly in HTML, and "print to PDF" doesn't do a good job with all the SVG pseudo-animations or show the speaker notes.
Hi, I’d like to contribute a documentation PR for this issue.
I’m planning a short section in the Extending and Embedding guide explaining how long-running C extensions can remain interruptible, with a small example using PyErr_CheckSignals(). I’d also cover error handling and cleanup, thread-state requirements, and the fact that checking signals can execute Python code.
Would this scope be useful? Suggestions on placement or anything the example should cover would be appreciated.
Activity
zackw commentedon May 19, 2025
Please see https://research.owlfolio.org/pubs/2025-pyext-ctrlc-talk/ for additional exposition
AA-Turner commentedon May 19, 2025
Is there a PDF version?
zackw commentedon Apr 24, 2026
@AA-Turner Sorry, no, I wrote the slide deck directly in HTML, and "print to PDF" doesn't do a good job with all the SVG pseudo-animations or show the speaker notes.
shaury04 commentedon Oct 15, 2026
Hi, I’d like to contribute a documentation PR for this issue.
I’m planning a short section in the Extending and Embedding guide explaining how long-running C extensions can remain interruptible, with a small example using
PyErr_CheckSignals(). I’d also cover error handling and cleanup, thread-state requirements, and the fact that checking signals can execute Python code.Would this scope be useful? Suggestions on placement or anything the example should cover would be appreciated.
pythongh-134075: Document how to make C extensions interruptible