Skip to content

Commit ed664b8

Browse files
committed
Use a SIGINT to interrupt the remote on Unix
This unfortunately cannot be applied to Windows, which has no way to trigger a SIGINT signal in a remote process without running code inside of that process itself.
1 parent ec9d3bf commit ed664b8

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

Lib/pdb.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -3122,11 +3122,20 @@ def cmdloop(self):
31223122
self.process_payload(payload)
31233123

31243124
def send_interrupt(self):
3125-
print(
3126-
"\n*** Program will stop at the next bytecode instruction."
3127-
" (Use 'cont' to resume)."
3128-
)
3129-
sys.remote_exec(self.pid, self.interrupt_script)
3125+
if hasattr(signal, "pthread_kill"):
3126+
# On Unix, send a SIGINT to the remote process, which interrupts IO
3127+
# and makes it raise a KeyboardInterrupt on the main thread when
3128+
# PyErr_CheckSignals is called or the eval loop regains control.
3129+
os.kill(self.pid, signal.SIGINT)
3130+
else:
3131+
# On Windows, inject a remote script that calls Pdb.set_trace()
3132+
# when the eval loop regains control. This cannot interrupt IO, and
3133+
# also cannot interrupt statements executed at a PDB prompt.
3134+
print(
3135+
"\n*** Program will stop at the next bytecode instruction."
3136+
" (Use 'cont' to resume)."
3137+
)
3138+
sys.remote_exec(self.pid, self.interrupt_script)
31303139

31313140
def process_payload(self, payload):
31323141
match payload:

0 commit comments

Comments
 (0)