Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feed.xsnews.nl!border-3.ams.xsnews.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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; 'exception': 0.03; 'debugging': 0.05; 'completeness': 0.07; 'try:': 0.07; 'exit.': 0.09; 'frameworks,': 0.09; 'mode,': 0.09; 'received:155': 0.09; 'snippet': 0.09; 'url:activestate': 0.09; 'anyway': 0.11; 'gui': 0.11; 'accidental': 0.16; 'blocks': 0.16; 'conditional': 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'oct': 0.16; 'poll': 0.16; 'received:155.180': 0.16; 'received:155.180.234': 0.16; 'received:159.53': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:svr.bankone.net': 0.16; 'run.': 0.16; 'securities,': 0.16; 'true:': 0.16; 'try/except': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wed,': 0.16; 'wrote:': 0.17; 'thanks,': 0.18; 'to:name:python- list@python.org': 0.20; 'trying': 0.21; 'keyboard': 0.22; 'of.': 0.22; 'ignored.': 0.23; "python's": 0.23; 'received:169.254': 0.24; 'header:In-Reply-To:1': 0.25; '(which': 0.26; 'accuracy': 0.27; 'execution': 0.27; '+0100,': 0.29; 'block,': 0.29; "d'aprano": 0.29; 'loop,': 0.29; 'restart': 0.29; 'steven': 0.29; 'received:169': 0.29; 'url:code': 0.29; 'probably': 0.29; 'maybe': 0.29; 'header:Received:8': 0.30; 'code': 0.31; 'point': 0.31; '(and': 0.32; 'dies': 0.33; 'to:addr:python-list': 0.33; 'likely': 0.33; 'another': 0.33; 'needed': 0.35; 'fail': 0.35; 'subject:?': 0.35; 'something': 0.35; 'there': 0.35; 'next': 0.35; 'really': 0.36; 'except': 0.36; 'but': 0.36; 'depends': 0.36; 'subject:with': 0.36; 'charset:us-ascii': 0.36; 'why': 0.37; 'previous': 0.37; 'subject:: ': 0.38; 'store': 0.38; 'to:addr:python.org': 0.39; 'think': 0.40; 'your': 0.60; 'skip:u 10': 0.60; 'back': 0.62; 'information,': 0.63; 'url:email': 0.63; 'here': 0.65; 'legal': 0.65; 'treat': 0.65; 'subject': 0.66; 'purchase': 0.67; 'believe': 0.69; 'press': 0.71; 'sale': 0.76; 'andrea': 0.84; 'received:169.254.8': 0.84; 'recover': 0.84; 'transactions': 0.91; 'hand,': 0.97 X-DKIM: OpenDKIM Filter v2.1.3 sf3.jpmchase.com q9PKxK8j016996 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1351198760; bh=U0eopSu6u8r4V9/+EcZYOer+dWDWiNJjRH11V6m7zw0=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=Slm5CKY3aHIpVnKAzrUQGukF8WM4LZElLo9hFBiF8r4RnAafWIeI/ygR6UPBAnlTJ e2C2KfyZ0p8iGnuENHIk/ognX1G9gDFkM6V5JD1KyUpcJJToZisl8uRHJlapGb/ekU mIBEX8/Y3ScxX/RGH84Y659M4jgbBPPm439qVnh4= From: "Prasad, Ramit" To: "python-list@python.org" Subject: RE: resume execution after catching with an excepthook? Thread-Topic: resume execution after catching with an excepthook? Thread-Index: AQHNsk4tbm5KClblV0qRT+D1aqbMB5fKWCUAgAApbyA= Date: Thu, 25 Oct 2012 20:59:14 +0000 References: <5088929e$0$29978$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.67.79.47] Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-DLP-FWD: Yes Content-Type: text/plain; charset="us-ascii" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351198768 news.xs4all.nl 6905 [2001:888:2000:d::a6]:38106 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32164 andrea crotti wrote:=0D=0A> 2012/10/25 Steven D'Aprano :=0D=0A> > On Wed, 24 Oct 2012 13:51:30 +0100, an= drea crotti wrote:=0D=0A> >=0D=0A[snip]=0D=0A> > Without a try=2E=2E=2Eexce= pt block, execution will cease after an exception is=0D=0A> > caught, even = when using sys=2Eexcepthook=2E I don't believe that there is any=0D=0A> > w= ay to jump back to the line of code that just failed (and why would you,=0D= =0A> > it will just fail again) or the next line (which will likely fail be= cause=0D=0A> > the previous line failed)=2E=0D=0A> >=0D=0A> > I think the o= nly way you can do this is to write your own execution loop:=0D=0A> >=0D=0A= > > while True:=0D=0A> > try:=0D=0A> > run(next_command())=0D= =0A> > except KeyboardInterrupt:=0D=0A> > if confirm_quit():=0D= =0A> > break=0D=0A> >=0D=0A> >=0D=0A> > Of course you need to m= ake run() atomic, or use transactions that can be=0D=0A> > reverted or back= ed out of=2E How plausible this is depends on what you are=0D=0A> > trying = to do -- Python's Ctrl-C is not really designed to be ignored=2E=0D=0A> >= =0D=0A> > Perhaps a better approach would be to treat Ctrl-C as an uncondit= ional=0D=0A> > exit, and periodically poll the keyboard for another key pre= ss to use as=0D=0A> > a conditional exit=2E Here's a snippet of platform-sp= ecific code to get a=0D=0A> > key press:=0D=0A> >=0D=0A> > http://code=2Eac= tivestate=2Ecom/recipes/577977=0D=0A> >=0D=0A> > Note however that it block= s if there is no key press waiting=2E=0D=0A> >=0D=0A> > I suspect that you = may need a proper event loop, as provided by GUI=0D=0A> > frameworks, or cu= rses=2E=0D=0A> >=0D=0A> =0D=0A> Ok thanks, but here the point is not to res= ume something that is going=0D=0A> to fail again, just to avoid accidental = kill of processes that take a=0D=0A> long time=2E Probably needed only by = me in debugging mode, but anyway I=0D=0A> can do the simple try/except then= , thanks=2E=2E=0D=0A=0D=0AOn the other hand, if you store state externally = (pickle?) maybe =0D=0Ayou can just restart at the last "check point"=2E Tha= t way even if=0D=0Athe program dies you can recover on the next run=2E=0D= =0A=0D=0ARamit Prasad=0D=0A=0D=0A=0D=0AThis email is confidential and subje= ct to important disclaimers and=0D=0Aconditions including on offers for the= purchase or sale of=0D=0Asecurities, accuracy and completeness of informat= ion, viruses,=0D=0Aconfidentiality, legal privilege, and legal entity discl= aimers,=0D=0Aavailable at http://www=2Ejpmorgan=2Ecom/pages/disclosures/ema= il=2E