Show More
@@ -66,6 +66,9 b' MAIN_THREAD_ID = thread.get_ident()' | |||
|
66 | 66 | # Tag when runcode() is active, for exception handling |
|
67 | 67 | CODE_RUN = None |
|
68 | 68 | |
|
69 | # Default timeout for waiting for multithreaded shells (in seconds) | |
|
70 | GUI_TIMEOUT = 10 | |
|
71 | ||
|
69 | 72 | #----------------------------------------------------------------------------- |
|
70 | 73 | # This class is trivial now, but I want to have it in to publish a clean |
|
71 | 74 | # interface. Later when the internals are reorganized, code that uses this |
@@ -359,12 +362,15 b' class MTInteractiveShell(InteractiveShell):' | |||
|
359 | 362 | isthreaded = True |
|
360 | 363 | |
|
361 | 364 | def __init__(self,name,usage=None,rc=Struct(opts=None,args=None), |
|
362 |
user_ns=None,user_global_ns=None,banner2='', |
|
|
365 | user_ns=None,user_global_ns=None,banner2='', | |
|
366 | gui_timeout=GUI_TIMEOUT,**kw): | |
|
363 | 367 | """Similar to the normal InteractiveShell, but with threading control""" |
|
364 | 368 | |
|
365 | 369 | InteractiveShell.__init__(self,name,usage,rc,user_ns, |
|
366 | 370 | user_global_ns,banner2) |
|
367 | 371 | |
|
372 | # Timeout we wait for GUI thread | |
|
373 | self.gui_timeout = gui_timeout | |
|
368 | 374 | |
|
369 | 375 | # A queue to hold the code to be executed. |
|
370 | 376 | self.code_queue = Queue.Queue() |
@@ -408,11 +414,12 b' class MTInteractiveShell(InteractiveShell):' | |||
|
408 | 414 | # Case 2 |
|
409 | 415 | return True |
|
410 | 416 | |
|
411 |
# shortcut - if we are in worker thread, or the worker thread is not |
|
|
412 |
# execute directly (to allow recursion and prevent deadlock if |
|
|
413 | # in IPython construction) | |
|
417 | # shortcut - if we are in worker thread, or the worker thread is not | |
|
418 | # running, execute directly (to allow recursion and prevent deadlock if | |
|
419 | # code is run early in IPython construction) | |
|
414 | 420 | |
|
415 |
if (self.worker_ident is None |
|
|
421 | if (self.worker_ident is None | |
|
422 | or self.worker_ident == thread.get_ident() ): | |
|
416 | 423 | InteractiveShell.runcode(self,code) |
|
417 | 424 | return |
|
418 | 425 | |
@@ -423,7 +430,7 b' class MTInteractiveShell(InteractiveShell):' | |||
|
423 | 430 | |
|
424 | 431 | self.code_queue.put((code,completed_ev, received_ev)) |
|
425 | 432 | # first make sure the message was received, with timeout |
|
426 |
received_ev.wait( |
|
|
433 | received_ev.wait(self.gui_timeout) | |
|
427 | 434 | if not received_ev.isSet(): |
|
428 | 435 | # the mainloop is dead, start executing code directly |
|
429 | 436 | print "Warning: Timeout for mainloop thread exceeded" |
General Comments 0
You need to be logged in to leave comments.
Login now