Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'exception': 0.03; 'value,': 0.03; 'elif': 0.04; 'handler': 0.04; 'def': 0.10; 'to:name:python-list': 0.15; 'sys.exit(0)': 0.16; 'sys.exit(1)': 0.16; 'true:': 0.16; 'received:209.85.214.174': 0.21; 'skip:_ 20': 0.22; 'message-id:@mail.gmail.com': 0.27; 'skip:_ 10': 0.29; 'this.': 0.29; "i'm": 0.29; 'running': 0.32; 'to:addr:python- list': 0.33; "can't": 0.34; 'program,': 0.34; 'received:google.com': 0.34; 'subject:?': 0.35; 'continue': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'wanted': 0.36; 'subject:with': 0.36; 'possible': 0.37; 'received:209': 0.37; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'back': 0.62; 'receive': 0.71; 'execution,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=zrBZleQtVDwwoTLAr/cuoc5DL6M0AGotTV0XQWYu4Bs=; b=nj+u88x4a8KW88v2Uyk54qhP0wpwZJauMTlcxUpUoqqT640xKh+PEEr9zJzzAJljuf n5APLjTxdRadIBjpiPInd7fRJoobq9wlgB+fh6j3ZAcb4BNTrcYK3NDLiv5VMxze14lI O9ZDmdTusUKmuVg/xrOYAxo89reLLJoyzYeJljZZtq2GGruVnTbCEvQiSnyrYx6XGB6u QLzV+i43VM6MmT+el4JvYDxA/+oVgX9ojLu/ztjkY6AXEULAdp/VqQcxE+jKjhHNA6NA LO5RbpzxEZdIUS9aEJ/kJa5w96NJVX/lGvMeciASKSsPtt2rBS/nvS6r/adINIkGce9S kd9A== MIME-Version: 1.0 Date: Wed, 24 Oct 2012 13:51:30 +0100 Subject: resume execution after catching with an excepthook? From: andrea crotti To: python-list 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351083094 news.xs4all.nl 6951 [2001:888:2000:d::a6]:46493 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32035 So I would like to be able to ask for confirmation when I receive a C-c, and continue if the answer is "N/n". I'm already using an exception handler set with sys.excepthook, but I can't make it work with the confirm_exit, because it's going to quit in any case.. A possible solution would be to do a global "try/except KeyboardInterrupt", but since I already have an excepthook I wanted to use this. Any way to make it continue where it was running after the exception is handled? def confirm_exit(): while True: q = raw_input("This will quit the program, are you sure? [y/N]") if q in ('y', 'Y'): sys.exit(0) elif q in ('n', 'N'): print("Continuing execution") # just go back to normal execution, is it possible?? break def _exception_handler(etype, value, tb): if etype == KeyboardInterrupt: confirm_exit() else: sys.exit(1) def set_exception_handler(): sys.excepthook = _exception_handler