Avoid nested SIGINT handling

Chris Angelico rosuav at gmail.com
Sat Nov 13 16:58:41 EST 2021


On Sun, Nov 14, 2021 at 4:42 AM Mladen Gogala via Python-list
<python-list at python.org> wrote:
>
> On Thu, 11 Nov 2021 17:22:15 +1100, Chris Angelico wrote:
>
> > Threads aren't the point here - signals happen immediately.
>
> Actually, signals are not delivered immediately. Signals are delivered
> the next time the process gets its turn on CPU. The process scheduler
> will make process runnable and the process will check for any pending
> signals first and will execute the handler. It is possible to have
> several SIGINT signals pending, for instance when I nervously press ctrl-
> C several times. However, signals are not processed as a part of the
> normal flow of the process and are processed sequentially.. When the
> process finds a pending signal, it executes the registered signal
> handler. It's always the same signal handler, unless signal handler is
> changed within the signal handler. After the signals are delivered, the
> process continues its normal operation until its CPU quantum expires or
> until initiates a synchronous I/O operation, as is the case with all
> normal read operations.
> BTW, that's the case on both Unix/Linux systems and Windows systems.
>

Maybe at the C level, but none of that happens in Python :)

There's a very very small signal handler in CPython that just sets a
flag and then handles things separately.

ChrisA


More information about the Python-list mailing list