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