##// END OF EJS Templates
Merge pull request #12148 from meeseeksmachine/auto-backport-of-pr-12141-on-7.x...
Matthias Bussonnier -
r25547:58860c13 merge
parent child Browse files
Show More
@@ -1,6 +1,7 b''
1 1 import asyncio
2 2 import signal
3 3 import sys
4 import threading
4 5
5 6 from IPython.core.debugger import Pdb
6 7
@@ -70,18 +71,11 b' class TerminalPdb(Pdb):'
70 71 if not self.use_rawinput:
71 72 raise ValueError('Sorry ipdb does not support use_rawinput=False')
72 73
73 # In order to make sure that asyncio code written in the
74 # interactive shell doesn't interfere with the prompt, we run the
75 # prompt in a different event loop.
76 # If we don't do this, people could spawn coroutine with a
77 # while/true inside which will freeze the prompt.
78
79 try:
80 old_loop = asyncio.get_event_loop()
81 except RuntimeError:
82 # This happens when the user used `asyncio.run()`.
83 old_loop = None
84
74 # In order to make sure that prompt, which uses asyncio doesn't
75 # interfere with applications in which it's used, we always run the
76 # prompt itself in a different thread (we can't start an event loop
77 # within an event loop). This new thread won't have any event loop
78 # running, and here we run our prompt-loop.
85 79
86 80 self.preloop()
87 81
@@ -98,14 +92,25 b' class TerminalPdb(Pdb):'
98 92 self._ptcomp.ipy_completer.namespace = self.curframe_locals
99 93 self._ptcomp.ipy_completer.global_namespace = self.curframe.f_globals
100 94
101 asyncio.set_event_loop(self.pt_loop)
95 # Run the prompt in a different thread.
96 line = ''
97 keyboard_interrupt = False
98
99 def in_thread():
100 nonlocal line, keyboard_interrupt
102 101 try:
103 102 line = self.pt_app.prompt()
104 103 except EOFError:
105 104 line = 'EOF'
106 finally:
107 # Restore the original event loop.
108 asyncio.set_event_loop(old_loop)
105 except KeyboardInterrupt:
106 keyboard_interrupt = True
107
108 th = threading.Thread(target=in_thread)
109 th.start()
110 th.join()
111
112 if keyboard_interrupt:
113 raise KeyboardInterrupt
109 114
110 115 line = self.precmd(line)
111 116 stop = self.onecmd(line)
General Comments 0
You need to be logged in to leave comments. Login now