Skip to content

Commit 703510e

Browse files
authored
Merge pull request #610 from SylvainCorlay/split-python-specific
Move Python-specific bits to ipkernel
2 parents ae00576 + d011b03 commit 703510e

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

ipykernel/ipkernel.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
from IPython.utils.tokenutil import token_at_cursor, line_at_cursor
1414
from tornado import gen
1515
from traitlets import Instance, Type, Any, List, Bool, observe, observe_compat
16+
from zmq.eventloop.zmqstream import ZMQStream
1617

1718
from .comm import CommManager
1819
from .kernelbase import Kernel as KernelBase
1920
from .zmqshell import ZMQInteractiveShell
2021
from .eventloops import _use_appnope
21-
22+
from .debugger import Debugger
2223
from .compiler import XCachingCompiler
2324

2425
try:
@@ -44,6 +45,8 @@ class IPythonKernel(KernelBase):
4445
help="Set this flag to False to deactivate the use of experimental IPython completion APIs.",
4546
).tag(config=True)
4647

48+
debugpy_stream = Instance(ZMQStream, allow_none=True)
49+
4750
user_module = Any()
4851
@observe('user_module')
4952
@observe_compat
@@ -67,6 +70,13 @@ def _user_ns_changed(self, change):
6770
def __init__(self, **kwargs):
6871
super(IPythonKernel, self).__init__(**kwargs)
6972

73+
# Initialize the Debugger
74+
self.debugger = Debugger(self.log,
75+
self.debugpy_stream,
76+
self._publish_debug_event,
77+
self.debug_shell_socket,
78+
self.session)
79+
7080
# Initialize the InteractiveShell subclass
7181
self.shell = self.shell_class.instance(parent=self,
7282
profile_dir = self.profile_dir,
@@ -140,12 +150,20 @@ def __init__(self, **kwargs):
140150
'file_extension': '.py'
141151
}
142152

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

147164
def start(self):
148165
self.shell.exit_now = False
166+
self.debugpy_stream.on_recv(self.dispatch_debugpy, copy=False)
149167
super(IPythonKernel, self).start()
150168

151169
def set_parent(self, ident, parent, channel='shell'):
@@ -381,6 +399,10 @@ def do_complete(self, code, cursor_pos):
381399
'metadata' : {},
382400
'status' : 'ok'}
383401

402+
@gen.coroutine
403+
def do_debug_request(self, msg):
404+
return (yield self.debugger.process_request(msg))
405+
384406
def _experimental_do_complete(self, code, cursor_pos):
385407
"""
386408
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)