Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95165

Re: except block isn't catching exception

Date 2015-08-08 18:11 +1000
From Cameron Simpson <cs@zip.com.au>
Subject Re: except block isn't catching exception
References <CAPTjJmoXwUaHCyPw-ZPXAGWTeKKZ8F-rSLAadJ1ffjtwCJZvBg@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1333.1439021524.3674.python-list@python.org> (permalink)

Show all headers | View raw


On 08Aug2015 17:08, Chris Angelico <rosuav@gmail.com> wrote:
>On Sat, Aug 8, 2015 at 4:56 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
>> On Fri, Aug 7, 2015 at 8:44 PM, Chris Angelico <rosuav@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?

From:

  https://docs.python.org/3/library/signal.html#execution-of-python-signal-handlers

we have:

  A Python signal handler does not get executed inside the low-level (C) signal 
  handler. Instead, the low-level signal handler sets a flag which tells the 
  virtual machine to execute the corresponding Python signal handler at a later 
  point(for example at the next bytecode instruction).

and in the next section "Signals and threads" it says:

   Python signal handlers are always executed in the main Python thread, even 
   if the signal was received in another thread.

Cheers,
Cameron Simpson <cs@zip.com.au>

Meddle not in the affairs of dragons,
for you are crunchy and good with ketchup.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: except block isn't catching exception Cameron Simpson <cs@zip.com.au> - 2015-08-08 18:11 +1000

csiph-web