Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32138
| 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 | <rosuav@gmail.com> |
| 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 | <mailman.2758.1351083094.27098.python-list@python.org> <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 <rosuav@gmail.com> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2850.1351180934.27098.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
On Fri, Oct 26, 2012 at 2:31 AM, Hans Mulder <hansmu@xs4all.nl> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
resume execution after catching with an excepthook? andrea crotti <andrea.crotti.0@gmail.com> - 2012-10-24 13:51 +0100
Re: resume execution after catching with an excepthook? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-25 01:15 +0000
Re: resume execution after catching with an excepthook? andrea crotti <andrea.crotti.0@gmail.com> - 2012-10-25 15:27 +0100
Re: resume execution after catching with an excepthook? Chris Angelico <rosuav@gmail.com> - 2012-10-26 01:51 +1100
Re: resume execution after catching with an excepthook? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-25 15:40 +0000
RE: resume execution after catching with an excepthook? "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-10-25 20:59 +0000
Re: resume execution after catching with an excepthook? Hans Mulder <hansmu@xs4all.nl> - 2012-10-25 17:31 +0200
Re: resume execution after catching with an excepthook? Chris Angelico <rosuav@gmail.com> - 2012-10-26 03:02 +1100
csiph-web