except block isn't catching exception

Chris Angelico rosuav at gmail.com
Sat Aug 8 09:08:25 CEST 2015

On Sat, Aug 8, 2015 at 4:56 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Fri, Aug 7, 2015 at 8:44 PM, Chris Angelico <rosuav at gmail.com> wrote:
>> The exception isn't happening inside sock.accept(), as I explained. So
>> you can't catch it there.
> Where does the exception happen then? Your explanation only covered
> why the blocking call cannot be interrupted by it, not why the
> exception isn't simply raised when the blocking call finishes.

I'm not sure there's anything in the language spec about it; at least,
I can't find it. But the last time I was digging in the Python/C API,
there was a caveat that KeyboardInterrupt was raised *at some point
after* Ctrl-C was hit - a flag gets set, and after every N bytecode
instructions, the flag is checked, and then the signal gets raised. It
might happen on only some platforms, and I can't even find back the
page I was looking at when I read that. Maybe someone else knows?


More information about the Python-list mailing list