Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-121450: Make inline breakpoints use the most recent pdb instance#121451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gaogaotiantian merged 9 commits intopython:mainfromgaogaotiantian:pdb-singleton
Jul 11, 2024

Conversation

@gaogaotiantian
Copy link
Member

@gaogaotiantiangaogaotiantian commentedJul 6, 2024
edited by bedevere-appbot
Loading

pdb.set_trace() will use the most recent pdb instance created if there is one. A minor fix inbdb is introduced otherwise the debugger will stop inBdb.reset(). A small fix intest_pdb is also required because we need to make sure the instancepdb.set_trace is using the patched instance.

The common debugger experience won't be much different to the users. We never explain the implementation details ofpdb.set_trace in our documentation so I don't even see a conflict with existing documentation. Not sure if any new documentation is needed at this point.

@@ -0,0 +1 @@
Inline breakpoints (:func:`breakpoint` and:func:`pdb.set_trace()`) will use the most recent ``Pdb`` instance, instead of creating a new one.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
Inline breakpoints (:func:`breakpoint` and:func:`pdb.set_trace()`)will use themost recent``Pdb`` instance, instead of creating a new one.
Inline breakpoints (:func:`breakpoint` and:func:`pdb.set_trace()`)now reuse thesame``Pdb`` instance, instead of creating a new one each time.

@iritkatriel
Copy link
Member

Are you sure this can't change behaviour in some cases, where the pdb instance now has a different state? For example, what if the user added breakpoints at the prompt between two breakpoint() calls?

@gaogaotiantian
Copy link
MemberAuthor

This will change the behavior, in favor of the expectation, in some cases, and that's the reason of the change. Adding breakpoints is not impacted becausebdb uses a very weird pattern for holding breakpoints. All the breakpoints are stored as class members so everypdb instance can share all the breakpoints - I would guess originally it was designed this way simply to avoid multiple instance issues.

The behavior changes when user is debugging betweenbreakpoint() calls. Nowbreakpoint() will instantiate a newpdb instance, and lose all the instance specific data the user sets (for example, breakpoint commands, or display). So the user might set a command at a breakpoint like "print(a) when hitting this breakpoint". Then abreakpoint() hit, this command will be discarded forever.

@iritkatriel
Copy link
Member

This will change the behavior, in favor of the expectation, in some cases, and that's the reason of the change. Adding breakpoints is not impacted becausebdb uses a very weird pattern for holding breakpoints. All the breakpoints are stored as class members so everypdb instance can share all the breakpoints - I would guess originally it was designed this way simply to avoid multiple instance issues.

The behavior changes when user is debugging betweenbreakpoint() calls. Nowbreakpoint() will instantiate a newpdb instance, and lose all the instance specific data the user sets (for example, breakpoint commands, or display). So the user might set a command at a breakpoint like "print(a) when hitting this breakpoint". Then abreakpoint() hit, this command will be discarded forever.

This could surprise someone, so best explain it in what's new.

Lib/pdb.py Outdated

def__new__(self,*args,**kwargs):
Pdb._last_pdb_instance=super().__new__(self)
returnPdb._last_pdb_instance
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

what if we're creating this instance while debugging? It would overwrite the instance from the hard coded breakpoint, and this one will be reused at the next hard coded breakpoint. This is not what's intended right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe Pdb._last_pdb_instance should be set in set_trace().

Probably need a test for this scenario too.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You mean inPdb.set_trace()? That would make some sense, only enlist the instance when it explicitly takes over the tracing.

However, if the user somehow creates and uses a pdb instance before abreakpoint(), we really can't determine the purpose. It could be nested debugging (debug command in pdb which I think we should patch to make sure the_last_pdb_instance is not modified). Or the user could want a new instance, for example, in the test cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Not sure I understand. If you set_last_pdb_instance inPdb.set_trace() then you get clear semantics, and no other breakpoint interrupts with this. Is that not a good thing?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

No I agree that setting_last_pdb_instance inPdb.set_trace() is a good approach. And I just realized the nested debugging (debug command in pdb) usessys.call_tracing so it probably won't affect anything if we do it inPdb.set_trace(). I'll do the change and see how it works out.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

And this change actually made the test change unnecessary so it's good. Do you think we need to test more scenarios? I think the case where users explicitly create aPdb instance in the pdb prompt is really rare - what's the point?

@iritkatriel
Copy link
Member

LGTM.

Still needs a what's new entry, I think.

Copy link
Member

@iritkatrieliritkatriel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM, add a what's new entry and it's good to go.

@gaogaotiantiangaogaotiantian merged commit690b935 intopython:mainJul 11, 2024
@gaogaotiantiangaogaotiantian deleted the pdb-singleton branchJuly 11, 2024 02:54
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull requestJul 11, 2024
estyxx pushed a commit to estyxx/cpython that referenced this pull requestJul 17, 2024
bretello added a commit to bretello/pdbpp that referenced this pull requestOct 23, 2025
With 3.14, breakpoints use the most recently created Pdb instance,in order to maintain history, display commands etc.See gh-121450,python/cpython#121451
bretello added a commit to bretello/pdbpp that referenced this pull requestOct 26, 2025
With 3.14, breakpoints use the most recently created Pdb instance,in order to maintain history, display commands etc.See gh-121450,python/cpython#121451
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@iritkatrieliritkatrieliritkatriel approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@gaogaotiantian@iritkatriel

[8]ページ先頭

©2009-2025 Movatter.jp