##// END OF EJS Templates
Backport PR #13311: Use ThreadPoolExecutor for debugger cmdloop, solving infinite thread-creation and traceback loop
Matthias Bussonnier -
Show More
@@ -1,10 +1,8 b''
1 import asyncio
1 import asyncio
2 import signal
2 import signal
3 import sys
3 import sys
4 import threading
5
4
6 from IPython.core.debugger import Pdb
5 from IPython.core.debugger import Pdb
7
8 from IPython.core.completer import IPCompleter
6 from IPython.core.completer import IPCompleter
9 from .ptutils import IPythonPTCompleter
7 from .ptutils import IPythonPTCompleter
10 from .shortcuts import create_ipython_shortcuts, suspend_to_bg, cursor_in_leading_ws
8 from .shortcuts import create_ipython_shortcuts, suspend_to_bg, cursor_in_leading_ws
@@ -18,6 +16,7 b' from pygments.token import Token'
18 from prompt_toolkit.shortcuts.prompt import PromptSession
16 from prompt_toolkit.shortcuts.prompt import PromptSession
19 from prompt_toolkit.enums import EditingMode
17 from prompt_toolkit.enums import EditingMode
20 from prompt_toolkit.formatted_text import PygmentsTokens
18 from prompt_toolkit.formatted_text import PygmentsTokens
19 from concurrent.futures import ThreadPoolExecutor
21
20
22 from prompt_toolkit import __version__ as ptk_version
21 from prompt_toolkit import __version__ as ptk_version
23 PTK3 = ptk_version.startswith('3.')
22 PTK3 = ptk_version.startswith('3.')
@@ -30,6 +29,7 b' class TerminalPdb(Pdb):'
30 Pdb.__init__(self, *args, **kwargs)
29 Pdb.__init__(self, *args, **kwargs)
31 self._ptcomp = None
30 self._ptcomp = None
32 self.pt_init(pt_session_options)
31 self.pt_init(pt_session_options)
32 self.thread_executor = ThreadPoolExecutor(1)
33
33
34 def pt_init(self, pt_session_options=None):
34 def pt_init(self, pt_session_options=None):
35 """Initialize the prompt session and the prompt loop
35 """Initialize the prompt session and the prompt loop
@@ -102,7 +102,7 b' class TerminalPdb(Pdb):'
102 if intro is not None:
102 if intro is not None:
103 self.intro = intro
103 self.intro = intro
104 if self.intro:
104 if self.intro:
105 self.stdout.write(str(self.intro)+"\n")
105 print(self.intro, file=self.stdout)
106 stop = None
106 stop = None
107 while not stop:
107 while not stop:
108 if self.cmdqueue:
108 if self.cmdqueue:
@@ -112,24 +112,11 b' class TerminalPdb(Pdb):'
112 self._ptcomp.ipy_completer.global_namespace = self.curframe.f_globals
112 self._ptcomp.ipy_completer.global_namespace = self.curframe.f_globals
113
113
114 # Run the prompt in a different thread.
114 # Run the prompt in a different thread.
115 line = ''
115 try:
116 keyboard_interrupt = False
116 line = self.thread_executor.submit(self.pt_app.prompt).result()
117
117 except EOFError:
118 def in_thread():
118 line = "EOF"
119 nonlocal line, keyboard_interrupt
119
120 try:
121 line = self.pt_app.prompt()
122 except EOFError:
123 line = 'EOF'
124 except KeyboardInterrupt:
125 keyboard_interrupt = True
126
127 th = threading.Thread(target=in_thread)
128 th.start()
129 th.join()
130
131 if keyboard_interrupt:
132 raise KeyboardInterrupt
133 line = self.precmd(line)
120 line = self.precmd(line)
134 stop = self.onecmd(line)
121 stop = self.onecmd(line)
135 stop = self.postcmd(stop, line)
122 stop = self.postcmd(stop, line)
General Comments 0
You need to be logged in to leave comments. Login now