Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32138

Re: resume execution after catching with an excepthook?

References <mailman.2758.1351083094.27098.python-list@python.org> <50895b4f$0$6931$e4fe514c@news2.news.xs4all.nl>
Date 2012-10-26 03:02 +1100
Subject Re: resume execution after catching with an excepthook?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2850.1351180934.27098.python-list@python.org> (permalink)

Show all headers | 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 | NextPrevious in thread | Find similar | Unroll thread


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