Skip to content

Commit 0bc51f2

Browse files
authored
Do not import debugger/debugpy unless needed (#1223)
1 parent 772dfb8 commit 0bc51f2

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

ipykernel/ipkernel.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from .comm.comm import BaseComm
2222
from .comm.manager import CommManager
2323
from .compiler import XCachingCompiler
24-
from .debugger import Debugger, _is_debugpy_available
2524
from .eventloops import _use_appnope
2625
from .iostream import OutStream
2726
from .kernelbase import Kernel as KernelBase
@@ -75,9 +74,7 @@ class IPythonKernel(KernelBase):
7574
help="Set this flag to False to deactivate the use of experimental IPython completion APIs.",
7675
).tag(config=True)
7776

78-
debugpy_socket = (
79-
Instance(zmq.asyncio.Socket, allow_none=True) if _is_debugpy_available else None
80-
)
77+
debugpy_socket = Instance(zmq.asyncio.Socket, allow_none=True)
8178

8279
user_module = Any()
8380

@@ -107,6 +104,8 @@ def __init__(self, **kwargs):
107104

108105
self.executing_blocking_code_in_main_shell = False
109106

107+
from .debugger import Debugger, _is_debugpy_available
108+
110109
# Initialize the Debugger
111110
if _is_debugpy_available:
112111
self.debugger = Debugger(
@@ -214,13 +213,17 @@ async def process_debugpy(self):
214213
tg.cancel_scope.cancel()
215214

216215
async def receive_debugpy_messages(self):
216+
from .debugger import _is_debugpy_available
217+
217218
if not _is_debugpy_available:
218219
return
219220

220221
while True:
221222
await self.receive_debugpy_message()
222223

223224
async def receive_debugpy_message(self, msg=None):
225+
from .debugger import _is_debugpy_available
226+
224227
if not _is_debugpy_available:
225228
return
226229

@@ -506,6 +509,8 @@ def do_complete(self, code, cursor_pos):
506509

507510
async def do_debug_request(self, msg):
508511
"""Handle a debug request."""
512+
from .debugger import _is_debugpy_available
513+
509514
if _is_debugpy_available:
510515
return await self.debugger.process_request(msg)
511516
return None

0 commit comments

Comments
 (0)