Skip to content

Commit

Permalink
Backport PR #1223 on branch 6.x (Do not import debugger/debugpy unles…
Browse files Browse the repository at this point in the history
…s needed) (#1224)
  • Loading branch information
krassowski authored Mar 27, 2024
1 parent 384bdb1 commit 1cea533
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from .comm.comm import BaseComm
from .comm.manager import CommManager
from .compiler import XCachingCompiler
from .debugger import Debugger, _is_debugpy_available
from .eventloops import _use_appnope
from .iostream import OutStream
from .kernelbase import Kernel as KernelBase
Expand Down Expand Up @@ -81,7 +80,7 @@ class IPythonKernel(KernelBase):
help="Set this flag to False to deactivate the use of experimental IPython completion APIs.",
).tag(config=True)

debugpy_stream = Instance(ZMQStream, allow_none=True) if _is_debugpy_available else None
debugpy_stream = Instance(ZMQStream, allow_none=True)

user_module = Any()

Expand Down Expand Up @@ -109,6 +108,8 @@ def __init__(self, **kwargs):
"""Initialize the kernel."""
super().__init__(**kwargs)

from .debugger import Debugger, _is_debugpy_available

# Initialize the Debugger
if _is_debugpy_available:
self.debugger = Debugger(
Expand Down Expand Up @@ -209,6 +210,8 @@ def __init__(self, **kwargs):
}

def dispatch_debugpy(self, msg):
from .debugger import _is_debugpy_available

if _is_debugpy_available:
# The first frame is the socket id, we can drop it
frame = msg[1].bytes.decode("utf-8")
Expand Down Expand Up @@ -524,6 +527,8 @@ def do_complete(self, code, cursor_pos):

async def do_debug_request(self, msg):
"""Handle a debug request."""
from .debugger import _is_debugpy_available

if _is_debugpy_available:
return await self.debugger.process_request(msg)
return None
Expand Down

0 comments on commit 1cea533

Please sign in to comment.