Skip to content

Commit

Permalink
Do not import debugger/debugpy unless needed (#1223)
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski authored Mar 25, 2024
1 parent 772dfb8 commit 0bc51f2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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 @@ -75,9 +74,7 @@ class IPythonKernel(KernelBase):
help="Set this flag to False to deactivate the use of experimental IPython completion APIs.",
).tag(config=True)

debugpy_socket = (
Instance(zmq.asyncio.Socket, allow_none=True) if _is_debugpy_available else None
)
debugpy_socket = Instance(zmq.asyncio.Socket, allow_none=True)

user_module = Any()

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

self.executing_blocking_code_in_main_shell = False

from .debugger import Debugger, _is_debugpy_available

# Initialize the Debugger
if _is_debugpy_available:
self.debugger = Debugger(
Expand Down Expand Up @@ -214,13 +213,17 @@ async def process_debugpy(self):
tg.cancel_scope.cancel()

async def receive_debugpy_messages(self):
from .debugger import _is_debugpy_available

if not _is_debugpy_available:
return

while True:
await self.receive_debugpy_message()

async def receive_debugpy_message(self, msg=None):
from .debugger import _is_debugpy_available

if not _is_debugpy_available:
return

Expand Down Expand Up @@ -506,6 +509,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 0bc51f2

Please sign in to comment.