This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Chun-Yu Tseng
Recipients Chun-Yu Tseng, georg.brandl, xdegaye
Date 2016-12-15.12:15:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1481804107.9.0.926871883552.issue22135@psf.upfronthosting.co.za>
In-reply-to
Content
Here comes the patch:

1. Let Pdb can also resume from `return`, `until` and `next` commands when receiving Control-C.

2. Explicitly raise `bdb.BdbQuit` when an unexpected exception occurs in `sigint_handler`. See #24283.

3. Add two tests `test_break_during_interactive_input`, `test_resume_from_sigint` and some helper functions to `test_pdb.py` to make sure that Pdb behaves as we expected.
See below, Pdb resumes back in a wrong position when receiving Control-C.  The environment is Python 3.5.2 (Mac).  But Pdb works right in latest 3.5/3.6/default now. So we should have tests here.
(Pdb) list
  1      import time
  2      def f():
  3          import pdb; pdb.Pdb().set_trace();
  4  ->        delay()
  5          print("***** f() done *****")
  6
  7      def delay():
  8          time.sleep(3)
  (Pdb) c
^C
Program interrupted. (Use 'cont' to resume).
--Call--
> /usr/local/var/pyenv/versions/3.5.2/lib/python3.5/signal.py(45)signal()
-> @_wraps(_signal.signal)
(Pdb)



What this patch does NOT do are:

1. Let Pdb can resume from `step` command.
I tried by the same way like what I did for `continue/return/until/next` commands, but Pdb resumed back at the beginning of `sigint_handler`. The user should type in `continue` to go to the right place. I can't find an elegant way to work around it:
-> time.sleep(3)
(Pdb) s
^C--Call--
> /Users/chun-yutseng/Projects/cpython/Lib/pdb.py(189)sigint_handler()
-> def sigint_handler(self, signum, frame):
(Pdb) l
184              self.commands_defining = False # True while in the process of defining
185                                             # a command list
186              self.commands_bnum = None # The breakpoint number for which we are
187                                        # defining a list
188
189  ->        def sigint_handler(self, signum, frame):
190              if self.allow_kbdint:
191                  raise KeyboardInterrupt
192              try:
193                  self.message("\nProgram interrupted.")
194
(Pdb)

2. Let the two added tests can be run on Windows.
I tried, but when I found that I may need to use Windows-specific signals (CTRL_C_EVENT/CTRL_BREAK_EVENT) in `pdb.py` to let automated tests pass, I decided not to introduce such complexity.
So I use `@unittest.skipIf` to skip these two tests and tested the patch on Windows manually.


Call for review/advice/guides, please.
History
Date User Action Args
2016-12-15 12:15:08Chun-Yu Tsengsetrecipients: + Chun-Yu Tseng, georg.brandl, xdegaye
2016-12-15 12:15:07Chun-Yu Tsengsetmessageid: <1481804107.9.0.926871883552.issue22135@psf.upfronthosting.co.za>
2016-12-15 12:15:07Chun-Yu Tsenglinkissue22135 messages
2016-12-15 12:15:07Chun-Yu Tsengcreate