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: 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 To: Python 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: User-Agent: Mutt/1.5.23 (2014-03-12) References: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On 08Aug2015 17:08, Chris Angelico wrote: >On Sat, Aug 8, 2015 at 4:56 PM, Ian Kelly wrote: >> On Fri, Aug 7, 2015 at 8:44 PM, Chris Angelico 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? =46rom: 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) si= gnal=20 handler. Instead, the low-level signal handler sets a flag which tells th= e=20 virtual machine to execute the corresponding Python signal handler at a l= ater=20 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, ev= en=20 if the signal was received in another thread. Cheers, Cameron Simpson Meddle not in the affairs of dragons, for you are crunchy and good with ketchup.