Skip to content

Commit 5e5fff4

Browse files
committed
Move Python-specific bits to ipkernel
1 parent ae00576 commit 5e5fff4

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

ipykernel/ipkernel.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .kernelbase import Kernel as KernelBase
1919
from .zmqshell import ZMQInteractiveShell
2020
from .eventloops import _use_appnope
21-
21+
from .debugger import Debugger
2222
from .compiler import XCachingCompiler
2323

2424
try:
@@ -44,6 +44,8 @@ class IPythonKernel(KernelBase):
4444
help="Set this flag to False to deactivate the use of experimental IPython completion APIs.",
4545
).tag(config=True)
4646

47+
debugpy_stream = Instance(ZMQStream, allow_none=True)
48+
4749
user_module = Any()
4850
@observe('user_module')
4951
@observe_compat
@@ -67,6 +69,13 @@ def _user_ns_changed(self, change):
6769
def __init__(self, **kwargs):
6870
super(IPythonKernel, self).__init__(**kwargs)
6971

72+
# Initialize the Debugger
73+
self.debugger = Debugger(self.log,
74+
self.debugpy_stream,
75+
self._publish_debug_event,
76+
self.debug_shell_socket,
77+
self.session)
78+
7079
# Initialize the InteractiveShell subclass
7180
self.shell = self.shell_class.instance(parent=self,
7281
profile_dir = self.profile_dir,
@@ -140,12 +149,20 @@ def __init__(self, **kwargs):
140149
'file_extension': '.py'
141150
}
142151

152+
@gen.coroutine
153+
def dispatch_debugpy(self, msg):
154+
# The first frame is the socket id, we can drop it
155+
frame = msg[1].bytes.decode('utf-8')
156+
self.log.debug("Debugpy received: %s", frame)
157+
self.debugger.tcp_client.receive_dap_frame(frame)
158+
143159
@property
144160
def banner(self):
145161
return self.shell.banner
146162

147163
def start(self):
148164
self.shell.exit_now = False
165+
self.debugpy_stream.on_recv(self.dispatch_debugpy, copy=False)
149166
super(IPythonKernel, self).start()
150167

151168
def set_parent(self, ident, parent, channel='shell'):
@@ -381,6 +398,10 @@ def do_complete(self, code, cursor_pos):
381398
'metadata' : {},
382399
'status' : 'ok'}
383400

401+
@gen.coroutine
402+
def do_debug_request(self, msg):
403+
return (yield self.debugger.process_request(msg))
404+
384405
def _experimental_do_complete(self, code, cursor_pos):
385406
"""
386407
Experimental completions from IPython, using Jedi.

ipykernel/kernelbase.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import time
1313
import uuid
1414
import warnings
15-
import asyncio
1615

1716
try:
1817
# jupyter_client >= 5, use tz-aware now
@@ -40,7 +39,6 @@
4039

4140
from ._version import kernel_protocol_version
4241

43-
from .debugger import Debugger
4442

4543
class Kernel(SingletonConfigurable):
4644

@@ -71,7 +69,6 @@ def shell_streams(self):
7169
return [shell_stream]
7270

7371
control_stream = Instance(ZMQStream, allow_none=True)
74-
debugpy_stream = Instance(ZMQStream, allow_none=True)
7572

7673
debug_shell_socket = Any()
7774

@@ -180,23 +177,10 @@ def __init__(self, **kwargs):
180177
for msg_type in self.control_msg_types:
181178
self.control_handlers[msg_type] = getattr(self, msg_type)
182179

183-
self.debugger = Debugger(self.log,
184-
self.debugpy_stream,
185-
self._publish_debug_event,
186-
self.debug_shell_socket,
187-
self.session)
188-
189180
self.control_queue = Queue()
190181
if 'control_thread' in kwargs:
191182
kwargs['control_thread'].io_loop.add_callback(self.poll_control_queue)
192183

193-
@gen.coroutine
194-
def dispatch_debugpy(self, msg):
195-
# The first frame is the socket id, we can drop it
196-
frame = msg[1].bytes.decode('utf-8')
197-
self.log.debug("Debugpy received: %s", frame)
198-
self.debugger.tcp_client.receive_dap_frame(frame)
199-
200184
@gen.coroutine
201185
def dispatch_control(self, msg):
202186
self.control_queue.put_nowait(msg)
@@ -440,7 +424,6 @@ def start(self):
440424
self.io_loop.add_callback(self.dispatch_queue)
441425

442426
self.control_stream.on_recv(self.dispatch_control, copy=False)
443-
self.debugpy_stream.on_recv(self.dispatch_debugpy, copy=False)
444427

445428
self.shell_stream.on_recv(
446429
partial(
@@ -752,7 +735,7 @@ def debug_request(self, stream, ident, parent):
752735

753736
@gen.coroutine
754737
def do_debug_request(self, msg):
755-
return (yield self.debugger.process_request(msg))
738+
raise NotImplementedError
756739

757740
#---------------------------------------------------------------------------
758741
# Engine methods (DEPRECATED)

0 commit comments

Comments
 (0)