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


Groups > comp.lang.python > #95165

Re: except block isn't catching exception

Path csiph.com!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <cameron@cskk.homeip.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'handler': 0.04; 'executed': 0.07; 'caveat': 0.09; 'handler.': 0.09; 'handlers': 0.09; 'it;': 0.09; 'knows?': 0.09; 'raised.': 0.09; 'spec': 0.09; 'python': 0.10; 'exception': 0.13; '>on': 0.16; 'api,': 0.16; 'bytecode': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'low-level': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'python/c': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'received:optusnet.com.au': 0.16; 'received:syd.optusnet.com.au': 0.16; 'set,': 0.16; 'simpson': 0.16; 'subject:exception': 0.16; 'then?': 0.16; 'thread.': 0.16; 'wrote:': 0.16; 'later': 0.16; 'have:': 0.18; 'tells': 0.18; 'language': 0.19; '>>>': 0.20; '2015': 0.20; 'aug': 0.20; 'machine': 0.21; 'cheers,': 0.22; 'sat,': 0.23; 'sets': 0.23; 'header:In-Reply-To:1': 0.24; 'header :User-Agent:1': 0.26; 'example': 0.26; 'chris': 0.26; 'fri,': 0.27; 'blocking': 0.29; 'thread,': 0.29; '(c)': 0.29; 'there.': 0.30; 'that.': 0.30; 'another': 0.32; "can't": 0.32; 'maybe': 0.33; 'point': 0.33; 'url:python': 0.33; 'instead,': 0.33; 'raised': 0.33; 'received:com.au': 0.33; 'covered': 0.34; 'gets': 0.35; 'next': 0.35; 'platforms,': 0.35; 'skip:> 10': 0.35; "isn't": 0.35; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'virtual': 0.38; 'anything': 0.38; 'someone': 0.38; 'why': 0.39; 'sure': 0.39; 'does': 0.39; 'from:': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'some': 0.40; 'url:3': 0.60; 'your': 0.60; 'back': 0.62; 'cameron': 0.66; 'interrupted': 0.76; 'to:name:python': 0.84; 'affairs': 0.91
Date Sat, 8 Aug 2015 18:11:48 +1000
From Cameron Simpson <cs@zip.com.au>
To Python <python-list@python.org>
Subject Re: except block isn't catching exception
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii; format=flowed
Content-Disposition inline
Content-Transfer-Encoding quoted-printable
In-Reply-To <CAPTjJmoXwUaHCyPw-ZPXAGWTeKKZ8F-rSLAadJ1ffjtwCJZvBg@mail.gmail.com>
User-Agent Mutt/1.5.23 (2014-03-12)
References <CAPTjJmoXwUaHCyPw-ZPXAGWTeKKZ8F-rSLAadJ1ffjtwCJZvBg@mail.gmail.com>
X-Optus-CM-Score 0
X-Optus-CM-Analysis v=2.1 cv=XMDNMlVE c=1 sm=1 tr=0 a=7VRakydLWw4CnqwyGz1TSg==:117 a=7VRakydLWw4CnqwyGz1TSg==:17 a=ZtCCktOnAAAA:8 a=PO7r1zJSAAAA:8 a=vrnE16BAAAAA:8 a=yEdEr6MRgwAA:10 a=kj9zAlcOel0A:10 a=uRRa74qj2VoA:10 a=pGLkceISAAAA:8 a=8AHkEIZyAAAA:8 a=1DKbE3JsI3Pum7Ys07QA:9 a=CjuIK1q_8ugA:10 a=uUPNzqFjAkUA:10
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1333.1439021524.3674.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1439021524 news.xs4all.nl 2957 [2001:888:2000:d::a6]:50305
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:95165

Show key headers only | 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