How does ^C work in Python?

Daniel Franke dfoxfranke at
Mon Sep 26 15:57:15 UTC 2016

In Python, there's a minimal generic interrupt handler which calls
Py_AddPendingCall() to schedule a call to a more complete handler. The
main interpreter loop then calls Py_MakePendingCalls() every few
iterations or on return from any system call. The default behavior for
handling SIGINT is to raise a KeyboardInterrupt exception. User code
can catch this exception and handle it. Since the handling code runs
from the main stack, there's no restriction on what library calls it
can safely make.

On 9/26/16, Hal Murray <hmurray at> wrote:
> I'm thinking about the python version of ntpq.  It needs a way to break out
> of commands that are taking too long.
> longjmp basically isn't guaranteed to work in c unless you can guarantee
> that
> the signal won't happen in the middle of any library routines.  They don't
> list the ones that might not work, only a few that are guaranteed to work.
> --
> These are my opinions.  I hate spam.
> _______________________________________________
> devel mailing list
> devel at

More information about the devel mailing list