MCPcopy Create free account
hub / github.com/ipython/ipython / cmdloop

Method cmdloop

IPython/terminal/debugger.py:84–140  ·  view source on GitHub ↗

Repeatedly issue a prompt, accept input, parse an initial prefix off the received input, and dispatch to action methods, passing them the remainder of the line as argument. override the same methods from cmd.Cmd to provide prompt toolkit replacement.

(self, intro=None)

Source from the content-addressed store, hash-verified

82 self.pt_app = PromptSession(**options)
83
84 def cmdloop(self, intro=None):
85 """Repeatedly issue a prompt, accept input, parse an initial prefix
86 off the received input, and dispatch to action methods, passing them
87 the remainder of the line as argument.
88
89 override the same methods from cmd.Cmd to provide prompt toolkit replacement.
90 """
91 if not self.use_rawinput:
92 raise ValueError('Sorry ipdb does not support use_rawinput=False')
93
94 # In order to make sure that prompt, which uses asyncio doesn't
95 # interfere with applications in which it's used, we always run the
96 # prompt itself in a different thread (we can't start an event loop
97 # within an event loop). This new thread won't have any event loop
98 # running, and here we run our prompt-loop.
99
100 self.preloop()
101
102 try:
103 if intro is not None:
104 self.intro = intro
105 if self.intro:
106 self.stdout.write(str(self.intro)+"\n")
107 stop = None
108 while not stop:
109 if self.cmdqueue:
110 line = self.cmdqueue.pop(0)
111 else:
112 self._ptcomp.ipy_completer.namespace = self.curframe_locals
113 self._ptcomp.ipy_completer.global_namespace = self.curframe.f_globals
114
115 # Run the prompt in a different thread.
116 line = ''
117 keyboard_interrupt = False
118
119 def in_thread():
120 nonlocal line, keyboard_interrupt
121 try:
122 line = self.pt_app.prompt()
123 except EOFError:
124 line = 'EOF'
125 except KeyboardInterrupt:
126 keyboard_interrupt = True
127
128 th = threading.Thread(target=in_thread)
129 th.start()
130 th.join()
131
132 if keyboard_interrupt:
133 raise KeyboardInterrupt
134
135 line = self.precmd(line)
136 stop = self.onecmd(line)
137 stop = self.postcmd(stop, line)
138 self.postloop()
139 except Exception:
140 raise
141

Callers

nothing calls this directly

Calls 3

popMethod · 0.80
writeMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected