mirror of
https://github.com/python/cpython.git
synced 2025-12-05 00:52:25 +00:00
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
This commit is contained in:
parent
635edd1990
commit
b90ffd88f1
2 changed files with 23 additions and 1 deletions
21
Lib/pdb.py
21
Lib/pdb.py
|
|
@ -371,7 +371,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
else:
|
else:
|
||||||
return self.handle_command_def(line)
|
return self.handle_command_def(line)
|
||||||
|
|
||||||
def handle_command_def(self,line):
|
def handle_command_def(self, line):
|
||||||
"""Handles one command line during command list definition."""
|
"""Handles one command line during command list definition."""
|
||||||
cmd, arg, line = self.parseline(line)
|
cmd, arg, line = self.parseline(line)
|
||||||
if not cmd:
|
if not cmd:
|
||||||
|
|
@ -457,14 +457,33 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
self.error("Usage: commands [bnum]\n ...\n end")
|
self.error("Usage: commands [bnum]\n ...\n end")
|
||||||
return
|
return
|
||||||
self.commands_bnum = bnum
|
self.commands_bnum = bnum
|
||||||
|
# Save old definitions for the case of a keyboard interrupt.
|
||||||
|
if bnum in self.commands:
|
||||||
|
old_command_defs = (self.commands[bnum],
|
||||||
|
self.commands_doprompt[bnum],
|
||||||
|
self.commands_silent[bnum])
|
||||||
|
else:
|
||||||
|
old_command_defs = None
|
||||||
self.commands[bnum] = []
|
self.commands[bnum] = []
|
||||||
self.commands_doprompt[bnum] = True
|
self.commands_doprompt[bnum] = True
|
||||||
self.commands_silent[bnum] = False
|
self.commands_silent[bnum] = False
|
||||||
|
|
||||||
prompt_back = self.prompt
|
prompt_back = self.prompt
|
||||||
self.prompt = '(com) '
|
self.prompt = '(com) '
|
||||||
self.commands_defining = True
|
self.commands_defining = True
|
||||||
try:
|
try:
|
||||||
self.cmdloop()
|
self.cmdloop()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
# Restore old definitions.
|
||||||
|
if old_command_defs:
|
||||||
|
self.commands[bnum] = old_command_defs[0]
|
||||||
|
self.commands_doprompt[bnum] = old_command_defs[1]
|
||||||
|
self.commands_silent[bnum] = old_command_defs[2]
|
||||||
|
else:
|
||||||
|
del self.commands[bnum]
|
||||||
|
del self.commands_doprompt[bnum]
|
||||||
|
del self.commands_silent[bnum]
|
||||||
|
self.error('command definition aborted, old commands restored')
|
||||||
finally:
|
finally:
|
||||||
self.commands_defining = False
|
self.commands_defining = False
|
||||||
self.prompt = prompt_back
|
self.prompt = prompt_back
|
||||||
|
|
|
||||||
|
|
@ -475,6 +475,9 @@ C-API
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- In pdb, when Ctrl-C is entered while defining commands for a
|
||||||
|
breakpoint, the old commands are restored.
|
||||||
|
|
||||||
- For traceback debugging, the pdb listing now also shows the locations
|
- For traceback debugging, the pdb listing now also shows the locations
|
||||||
where the exception was originally (re)raised, if it differs from the
|
where the exception was originally (re)raised, if it differs from the
|
||||||
last line executed (e.g. in case of finally clauses).
|
last line executed (e.g. in case of finally clauses).
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue