Show More
@@ -375,7 +375,8 b' class MTInteractiveShell(InteractiveShell):' | |||
|
375 | 375 | if not callable(t): |
|
376 | 376 | raise TypeError,'on_kill must be a list of callables' |
|
377 | 377 | self.on_kill = on_kill |
|
378 | ||
|
378 | # thread identity of the "worker thread" (that may execute code directly) | |
|
379 | self.worker_ident = None | |
|
379 | 380 | def runsource(self, source, filename="<input>", symbol="single"): |
|
380 | 381 | """Compile and run some source in the interpreter. |
|
381 | 382 | |
@@ -406,7 +407,14 b' class MTInteractiveShell(InteractiveShell):' | |||
|
406 | 407 | # Note that with macros and other applications, we MAY re-enter this |
|
407 | 408 | # section, so we have to acquire the lock with non-blocking semantics, |
|
408 | 409 | # else we deadlock. |
|
409 | got_lock = self.thread_ready.acquire() | |
|
410 | ||
|
411 | # shortcut - if we are in worker thread, execute directly (to allow recursion) | |
|
412 | ||
|
413 | if self.worker_ident == thread.get_ident(): | |
|
414 | InteractiveShell.runcode(self,code) | |
|
415 | return | |
|
416 | ||
|
417 | got_lock = self.thread_ready.acquire(blocking=False) | |
|
410 | 418 | self.code_queue.put(code) |
|
411 | 419 | if got_lock: |
|
412 | 420 | self.thread_ready.wait() # Wait until processed in timeout interval |
@@ -420,8 +428,8 b' class MTInteractiveShell(InteractiveShell):' | |||
|
420 | 428 | Multithreaded wrapper around IPython's runcode().""" |
|
421 | 429 | |
|
422 | 430 | global CODE_RUN |
|
423 | ||
|
424 | 431 | # lock thread-protected stuff |
|
432 | self.worker_ident = thread.get_ident() | |
|
425 | 433 | got_lock = self.thread_ready.acquire() |
|
426 | 434 | |
|
427 | 435 | if self._kill: |
@@ -448,7 +456,6 b' class MTInteractiveShell(InteractiveShell):' | |||
|
448 | 456 | code_to_run = self.code_queue.get_nowait() |
|
449 | 457 | except Queue.Empty: |
|
450 | 458 | break |
|
451 | ||
|
452 | 459 | # Exceptions need to be raised differently depending on which |
|
453 | 460 | # thread is active. This convoluted try/except is only there to |
|
454 | 461 | # protect against asynchronous exceptions, to ensure that a KBINT |
General Comments 0
You need to be logged in to leave comments.
Login now