Skip to content

gh-66333: Allow to break into pdb with Ctrl-C for all the commands t… - #13269

Open
devjoe wants to merge 2 commits into
python:mainfrom
devjoe:fix-issue-22135
Open

devjoe wants to merge 2 commits into
python:mainfrom
devjoe:fix-issue-22135

Conversation

@devjoe

@devjoe devjoe commented May 12, 2019 •

Copy link
Copy Markdown

This PR comes from https://bugs.python.org/issue22135.
I mainly use registered signal_handler to handle Ctrl-C behavior and add a unit test.

https://bugs.python.org/issue22135

Comment thread Lib/pdb.py Resolved
Comment thread Lib/pdb.py Resolved
Comment thread Lib/pdb.py Resolved
Comment thread Lib/pdb.py Resolved
@csabella
csabella requested a review from zware May 13, 2019 02:31
@devjoe

devjoe commented May 13, 2019

Copy link
Copy Markdown
Author

@blueyed thanks for your super fast feedback, will refine this PR in the following days.

@devjoe
devjoe force-pushed the fix-issue-22135 branch from 537e470 to 408e11d Compare May 18, 2019 17:09
@devjoe

devjoe commented May 18, 2019 •

Copy link
Copy Markdown
Author

PR updated, feel free to let me know your thoughts.

@devjoe

devjoe commented May 28, 2019

Copy link
Copy Markdown
Author

@blueyed 🙏

@blueyed

blueyed commented May 28, 2019

Copy link
Copy Markdown
Contributor

@devjoe
LGTM (only skimmed it quickly now), but I am not in the position to really judge / acknowledge it unfortunately.

@devjoe

devjoe commented Jul 7, 2019

Copy link
Copy Markdown
Author

@xdegaye sorry for bothering you, could help to review this PR again? 🙏

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Feb 20, 2026
@serhiy-storchaka serhiy-storchaka changed the title bpo-22135: Allow to break into pdb with Ctrl-C for all the commands t… gh-66333: Allow to break into pdb with Ctrl-C for all the commands t… Aug 12, 2026
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Aug 14, 2026
@devjoe

devjoe commented Oct 19, 2026

Copy link
Copy Markdown
Author

@gaogaotiantian
Thanks for your sharing in PyConTW 2026. It reminds me of this old PR and motivates me to wrap it up.

As of now, next, until, and return still have the same behavior (Ctrl+C interrupts the program with KeyboardInterrupt) in Linux and Windows.

Do you think it is worth making next, until, and return aligning to continue's behavior when Ctrl+C is fired?

@gaogaotiantian

Copy link
Copy Markdown
Member

What's the reason to change sigint_handler? Is it necessary? You also changed the behavior for ctrl+c in continue - is that indended as well?

@devjoe

devjoe commented Oct 21, 2026

Copy link
Copy Markdown
Author

In my original implementation, the reasons of changing sigint_handler were:

  1. Taking issue24283 into consideration, so a try ... catch is introduced
  2. Simplifying the logic for continue (removes redundant self.set_step() before self.set_step() because at 2019 self.set_step() is called in self.set_trace())
  3. Adding SIGINT handling for next , until , and return using self.set_step() . However, this does not reliably stop inside an already-running child frame that is not being traced.

Based on the current codebase, I propose the following scope for this PR:

  1. Ignore issue24283 and do not bring in such complexity here
  2. Remove the use of self.set_step() in sigint_handler to avoid an unwanted situation when any breakpoint exists (see the first snapshot below)
  3. Let next, until, return, and continue share the same architecture as possible (i.e. by using self.set_trace() in siginit_handler)
  4. Fix a handler restoration edge case when a user defines his own signal.signal(signal.SIGINT, new_handler) during continue (see the second snapshot below)

Would this be a reasonable scope for the PR?

image image

@gaogaotiantian

Copy link
Copy Markdown
Member

Let's handle one thing at a time. Can you just do the same mechanism in step, next and until as continue?

@devjoe

devjoe commented Oct 22, 2026

Copy link
Copy Markdown
Author

Sure. It makes the implementation easier and simpler.

Just to confirm the scope: you want to include step instead of return, right?

@python-cla-bot

python-cla-bot Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@read-the-docs-community

read-the-docs-community Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

@devjoe

devjoe commented Oct 28, 2026

Copy link
Copy Markdown
Author

@gaogaotiantian

I’ve revised the patch so that step, next, and until use the same SIGINT handling as continue.

The main changes are:

  1. Keep sigint_handler() as close to its existing implementation as possible.
  2. Remove the redundant self.set_step() call from sigint_handler(), since set_trace(frame) already sets up the next stop.
  3. Extract the SIGINT handler setup from do_continue() into a shared _install_sigint_handler() helper.
  4. Override dispatch_call() to avoid stepping into Pdb’s own SIGINT handler.
  5. Add tests for Ctrl-C during continue, step, next, and until.
  6. Save and restore SIGINT handler state around each doctest to prevent tests from affecting one another.

Feel free to let me know your thoughts.

Comment thread Lib/pdb.py Resolved
@devjoe

devjoe commented Nov 6, 2026

Copy link
Copy Markdown
Author

Added the support for return. Please take a look again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants