Mailing List Archive

Re: Avoid nested SIGINT handling
On 2021-11-10, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
> Hi!
>
> How do I handle a SIGINT (or any other signal) avoid nesting?

I don't think you need to. Python will only call signal handlers in
the main thread, so a handler can't be executed while another handler
is running anyway.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Avoid nested SIGINT handling [ In reply to ]
Às 21:55 de 10/11/21, Jon Ribbens escreveu:
> On 2021-11-10, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
>> Hi!
>>
>> How do I handle a SIGINT (or any other signal) avoid nesting?
>
> I don't think you need to. Python will only call signal handlers in
> the main thread, so a handler can't be executed while another handler
> is running anyway.
>

Do you mean that if I issue a ctrl+c while the previous one is
"processing" it is held until, at least, the "processing" returns?
--
https://mail.python.org/mailman/listinfo/python-list
Re: Avoid nested SIGINT handling [ In reply to ]
On Thu, Nov 11, 2021 at 5:01 PM Jon Ribbens via Python-list
<python-list@python.org> wrote:
>
> On 2021-11-10, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
> > Hi!
> >
> > How do I handle a SIGINT (or any other signal) avoid nesting?
>
> I don't think you need to. Python will only call signal handlers in
> the main thread, so a handler can't be executed while another handler
> is running anyway.

Threads aren't the point here - signals happen immediately.

Would it be easier to catch KeyboardInterrupt and do your processing
there, rather than actually catching SIGINT?

I'd recommend just trying what you have, and seeing if it's reentrant.
My suspicion is that it isn't, on a technical level (the Python
function will be queued for when it's safe to call it - probably after
the next bytecode instruction), but that your own code will still need
to worry about reentrancy.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list