My code is something like this: while not_done: try: code() except keyboardinterupt: print "Menu:" print " debug - run pdb" print " resume - resume program" print " abort - abort program" ... command = raw_input("> ") if command == "debug": pdb.set_trace() ...
The idea is that code() is run in a loop executing data (in my case, a single entry to a log file) and Ctrl-C pauses the program and pops up a little menu. The problem is that in certain cases, code() may have already altered data and breaking out and rerunning it will either 1) lose data or 2) duplicate data. The only real solution I can think of is catching the interrupt in a separate thread which sets a flag telling the main thread to run pdb, or abort or whatever, but ideally, I'd like to catch the exception and somehow magically resume. 2009/1/5 Ajurna <aju...@gmail.com>: > hi, > it might be me and im getting this wrong but surely you could use a try: > except clause? > > try: > codeloop() > except keyboardinterupt: > mainloop() > > > or something to that effect. > > On Mon, Jan 5, 2009 at 3:38 PM, Daniel Kersten <dkers...@gmail.com> wrote: >> >> Hi & happy new year, >> >> I'm wondering if theres anyway of resuming after a KeyboardInterrupt >> exception, if I catch it. For example, can I retrieve the code object >> or stack or something from when execution was interrupted and continue >> from there. >> >> Basically, I would like to use Ctrl-C as a way to temporarily break >> out of my program to enter a menu (in this particular case, the menu >> allows you to quit, continue and enter pdb). This works fine in most >> cases, but if I interrupt in the middle of certain operations, when I >> resume, I lose data. Of course, I can write my code to avoid this, but >> that may not always be possible. >> >> Any ideas? Or do I need to handle the menu in a separate thread..? >> >> Thanks! >> Dan. >> >> -- >> Daniel Kersten. >> Leveraging dynamic paradigms since the synergies of 1985. >> >> > > > > -- > ~Ajurna > > > > -- Daniel Kersten. Leveraging dynamic paradigms since the synergies of 1985. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Python Ireland" group. To post to this group, send email to pythonireland@googlegroups.com To unsubscribe from this group, send email to pythonireland+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.ie/group/pythonireland?hl=en -~----------~----~----~----~------~----~------~--~---