[Python-Dev] Problem with signals in a single threaded application (original) (raw)

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Jan 28 01:59:50 CET 2007


Martin v. Löwis wrote:

Greg Ewing schrieb:

Please try to come up with a patch (e.g. by putting a while(istripped) loop around the for loop). That isn't going to fix it. Why not?

Correct me if I'm wrong, but what I got from the OP was that the current method does

if (is_tripped) { for each signal { if the signal has occurred, call its handler } is_tripped = 0; }

and the problem is that any setting of is_tripped that occurs in the midst of calling the handlers gets wiped out at the end.

Changing this to

while (is_tripped) { for each signal { if the signal has occurred, call its handler } is_tripped = 0; }

doesn't solve that, because is_tripped still gets set to 0 before it's tested again.

Also, why does it need to clear istripped atomically?

Thinking about it more, probably it doesn't. What's important is to clear it before testing whether any handlers need to be called, i.e.

if (is_tripped) { is_tripped = 0; for each signal { if the signal has occurred, call its handler } }

If you really care, you can make that a while instead of an if so that you don't have to wait until the next CheckSignals. But if the signal had arrived a few microseconds later you'd have to do that anyway, so I don't see it as a big deal.

-- Greg



More information about the Python-Dev mailing list