##// END OF EJS Templates
Improve handling of KBINT in threaded shells. Closes #212....
fperez -
Show More
@@ -4,7 +4,7 b''
4 All the matplotlib support code was co-developed with John Hunter,
4 All the matplotlib support code was co-developed with John Hunter,
5 matplotlib's author.
5 matplotlib's author.
6
6
7 $Id: Shell.py 2997 2008-01-31 06:58:33Z fperez $"""
7 $Id: Shell.py 3001 2008-02-01 07:07:00Z fperez $"""
8
8
9 #*****************************************************************************
9 #*****************************************************************************
10 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
10 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
@@ -421,11 +421,8 b' class MTInteractiveShell(InteractiveShell):'
421
421
422 global CODE_RUN
422 global CODE_RUN
423
423
424 # Exceptions need to be raised differently depending on which thread is
425 # active
426 CODE_RUN = True
427 # lock thread-protected stuff
424 # lock thread-protected stuff
428 self.thread_ready.acquire()
425 got_lock = self.thread_ready.acquire()
429
426
430 if self._kill:
427 if self._kill:
431 print >>Term.cout, 'Closing threads...',
428 print >>Term.cout, 'Closing threads...',
@@ -451,8 +448,27 b' class MTInteractiveShell(InteractiveShell):'
451 code_to_run = self.code_queue.get_nowait()
448 code_to_run = self.code_queue.get_nowait()
452 except Queue.Empty:
449 except Queue.Empty:
453 break
450 break
454 InteractiveShell.runcode(self,code_to_run)
451
455
452 # Exceptions need to be raised differently depending on which
453 # thread is active. This convoluted try/except is only there to
454 # protect against asynchronous exceptions, to ensure that a KBINT
455 # at the wrong time doesn't deadlock everything. The global
456 # CODE_TO_RUN is set to true/false as close as possible to the
457 # runcode() call, so that the KBINT handler is correctly informed.
458 try:
459 CODE_RUN = True
460 InteractiveShell.runcode(self,code_to_run)
461 if got_lock:
462 CODE_RUN = False
463 except KeyboardInterrupt:
464 print "Keyboard interrupted in mainloop"
465 while not self.code_queue.empty():
466 self.code_queue.get_nowait()
467 break
468 finally:
469 if got_lock:
470 CODE_RUN = False
471
456 # We're done with thread-protected variables
472 # We're done with thread-protected variables
457 if code_to_run is not None:
473 if code_to_run is not None:
458 self.thread_ready.notify()
474 self.thread_ready.notify()
@@ -1,3 +1,8 b''
1 2008-02-01 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * IPython/Shell.py (MTInteractiveShell.runcode): Improve handling
4 of KBINT in threaded shells. After code provided by Marc in #212.
5
1 2008-01-30 Fernando Perez <Fernando.Perez@colorado.edu>
6 2008-01-30 Fernando Perez <Fernando.Perez@colorado.edu>
2
7
3 * IPython/Shell.py (MTInteractiveShell.__init__): Fixed deadlock
8 * IPython/Shell.py (MTInteractiveShell.__init__): Fixed deadlock
General Comments 0
You need to be logged in to leave comments. Login now