KeyboardInterrupt from syscalls
Dear List, I was writing a Python extension module, including a sleeping call to poll(2), and noticed, to my great surprise (and joy), that even when blocking there, KeyboardInterrupt still worked properly when sending SIGINTs to the interpreter. It really got me wondering how it works, though. I would have thought that I would have to check manually for interrupts in one way or another, seeing how the thread in question should be stuck in my syscall. Sure, I return on EINTR, but I only return Py_FALSE, not NULL, so I wouldn't have thought that the interpreter would look for an exception having taken place (I would assume that it gets set in the sighandler). So how does it work? Does my code get to return Py_FALSE, and the interpreter ignores it, seeing that an exception is set? Is a non-local exit performed right over my call stack (in which case my next question would be how to clean up resources being used from my C code)? Or does something completely else happen? Fredrik Tolf -- http://mail.python.org/mailman/listinfo/python-list
Re: KeyboardInterrupt from syscalls
Fredrik Tolf wrote: So how does it work? Does my code get to return Py_FALSE, and the interpreter ignores it, seeing that an exception is set? Is a non-local exit performed right over my call stack (in which case my next question would be how to clean up resources being used from my C code)? Or does something completely else happen? the signal handler adds an entry to a pending calls queue, which is checked by the interpreter at regular intervals. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: KeyboardInterrupt from syscalls
On Wed, 2006-11-22 at 19:45 +0100, Fredrik Lundh wrote: Fredrik Tolf wrote: So how does it work? Does my code get to return Py_FALSE, and the interpreter ignores it, seeing that an exception is set? Is a non-local exit performed right over my call stack (in which case my next question would be how to clean up resources being used from my C code)? Or does something completely else happen? the signal handler adds an entry to a pending calls queue, which is checked by the interpreter at regular intervals. I see. So if I get that right, that would mean that if I, in my function, would loop and retry when getting an EINTR instead of returning, a KeyboardInterrupt from e.g. Ctrl-C would be delayed until it has other reason to return? Thanks for your answer! Fredrik Tolf -- http://mail.python.org/mailman/listinfo/python-list