2

I need to catch a KeyboardInterrupt exception at any point in a large while loop but defer handling it at those points where I have all the balls in the air.

Specifically, I'm processing a MIDI file consisting of 2 and 3 byte midi events. I need to detect a KeyboardInterrupt at any time but I must never break off processing in the middle of a midi event.

Can someone please suggest the best way of doing this?

Blckknght
  • 100,903
  • 11
  • 120
  • 169
pleriche
  • 61
  • 5
  • 1
    At least tell us which programming language you use. – Guntram Blohm Mar 04 '14 at 12:31
  • Python 3 - sorry, I was thinking I was in a Python forum. – pleriche Mar 05 '14 at 14:14
  • 1
    Is http://stackoverflow.com/questions/4205317/capture-keyboardinterrupt-in-python-without-try-except what you're looking for? – James_pic Mar 05 '14 at 20:16
  • Thank you James_pic - best idea yet. But signals can be tricky to use without creating race conditions. If I create a handler for SIGINT which simply flags that ctrl-c has been received then returns, I'm not sure whether that may still have aborted a putbyte. If so, I'll still have the problem of knowing whether the byte made it out of the system or not. – pleriche Mar 06 '14 at 22:53
  • But can adapt the code there: In the event handler create new custom events that you put in a queue or similar. When you are ready, you process the queue. – Johannes Jasper May 04 '14 at 08:44

0 Answers0