Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Commit

Permalink
Make sure we use interruptible version of pdb
Browse files Browse the repository at this point in the history
  • Loading branch information
itamarst committed May 26, 2020
1 parent c0a03fb commit 5998702
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,11 @@ def init_pdb(self):
"""
import pdb
from IPython.core import debugger
debugger.Pdb = debugger.InterruptiblePdb
pdb.Pdb = debugger.Pdb
pdb.set_trace = debugger.set_trace
if hasattr(debugger, "InterruptiblePdb"):
# Only available in newer IPython releases:
debugger.Pdb = debugger.InterruptiblePdb
pdb.Pdb = debugger.Pdb
pdb.set_trace = debugger.set_trace

@catch_config_error
def initialize(self, argv=None):
Expand Down
21 changes: 21 additions & 0 deletions ipykernel/tests/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,24 @@ def test_interrupt_during_input():
reply = kc.get_shell_msg(timeout=TIMEOUT)
from .test_message_spec import validate_message
validate_message(reply, 'execute_reply', msg_id)


def test_interrupt_during_pdb_set_trace():
"""
The kernel exits after being interrupted while waiting in pdb.set_trace().
Merely testing input() isn't enough, pdb has its own issues that need
to be handled in addition.
"""
with new_kernel() as kc:
km = kc.parent
msg_id = kc.execute("import pdb; pdb.set_trace()")
msg_id2 = kc.execute("3 + 4")
time.sleep(1) # Make sure it's actually waiting for input.
km.interrupt_kernel()
# If we failed to interrupt interrupt, this will timeout:
from .test_message_spec import validate_message
reply = kc.get_shell_msg(timeout=TIMEOUT)
validate_message(reply, 'execute_reply', msg_id)
reply = kc.get_shell_msg(timeout=TIMEOUT)
validate_message(reply, 'execute_reply', msg_id2)

0 comments on commit 5998702

Please sign in to comment.