Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!news2.arglkargh.de!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.018 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'elif': 0.04; 'robust': 0.09; 'def': 0.10; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'handler)': 0.16; 'hits': 0.16; 'oct': 0.16; 'true:': 0.16; 'wrote:': 0.17; 'instance,': 0.17; 'import': 0.21; 'fairly': 0.21; 'received:209.85.214.174': 0.21; 'seems': 0.23; 'raise': 0.24; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'execution': 0.27; 'message-id:@mail.gmail.com': 0.27; 'about.': 0.29; "i'm": 0.29; 'fri,': 0.30; 'to:addr:python-list': 0.33; 'program,': 0.34; 'received:google.com': 0.34; 'subject:?': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'subject:with': 0.36; 'should': 0.36; '(for': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'skip:u 10': 0.60; 'back': 0.62; 'perfect': 0.63; '26,': 0.65; 'talking': 0.66; 'careful': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=n2Zz23WBBkl6Gwg5TDMgU4J68NVFW8ii1XfnCHCquPw=; b=DsXQOdlvKWqnpUHT+txyBLWoFKEfpYLQNFrpUJXd8jXdHdWKL/EG0mmcZSSnSVPQDm RJdm56pAkzApxRdXDqahMvgC0oz35Yf0SYzB3jh+wY+5VecAuUPLqf6IGe0rMR3+tVU5 3dxbGtvsvIHfMGB77ogS5zy2CrLsK+tOxw3uVeL9P1ikaDP693c002ZfLmos/L/wCDl3 N8YgXRSmAtaIcQh2zCiMaszmjywb7snqlrcaYNtIo67cK/fpaUk+znQk2m03tQHnitwV Jy0z5j2AN/c01RWt23LysVezd9zdeeLVO8G4OYEq/VwTF/mKS7bf1C4nUQCShHvX4NiT 3Gyg== MIME-Version: 1.0 In-Reply-To: <50895b4f$0$6931$e4fe514c@news2.news.xs4all.nl> References: <50895b4f$0$6931$e4fe514c@news2.news.xs4all.nl> Date: Fri, 26 Oct 2012 03:02:11 +1100 Subject: Re: resume execution after catching with an excepthook? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351180934 news.xs4all.nl 6881 [2001:888:2000:d::a6]:58092 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32138 On Fri, Oct 26, 2012 at 2:31 AM, Hans Mulder wrote: > This seems to work; I'm not sure how robust it is: > > import signal > > def handler(signum, frame): > while True: > q = raw_input("This will quit the program, are you sure? [y/N]") > if q[:1] in "yY": > raise KeyboardInterrupt > elif q[:1] in "nN": > print("Continuing execution") > # just go back to normal execution > return > > signal.signal(signal.SIGINT, handler) > Yes, that's what I was talking about. You do have to be fairly careful what you do (for instance, what should happen if the user hits Ctrl-C during handler()? Default is that it'll raise KeyboardInterrupt unconditionally), but you have perfect flexibility. ChrisA