-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
GH-100141: Fix Pdb loops endlessly on empty file #106467
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Confirming that this does seem to fix the problem, might be a good idea to introduce a regression test for this.
I'll note that changing |
I felt brave and decided that instead of changing a logic clause I don't understand and probably nobody does to a conditional that should never happen, I should just remove it, that way future devs will not stare at it in confusion, and we will get faster feedback if we broke something terrible. But I worked under the assumption that a core dev will have better insight than me :-) |
A couple of tests failed only on Windows x86 and then succeeded on second try. |
The current fix works fine for the current implementation, but it relies on the fact that a line event with PEP 669 says:
Obviously this extreme case violates the event definition. When the user executes an empty file, do we explicitly and purposely emitting a line event with line number 0? If that's a reliable feature, then this fix is good. Otherwise we need more as line event may never fire. @SonOfLilit , in any case, we need a regression test for this. Loading an empty file is much better than using |
Sure, I'll add one. And I guess since there is just one possible empty file, if we have a regression test we might feel comfortable with this even if it can be read as not promised by the spec? Alternatively, we can propose spec errata because obviously you'd want this event? |
The main concern is whether the monitoring code is working as expected. Having a There are actually more than one kind of empty file :). This would reproduce with any lines of comments in the "empty" file, as long as there's no compilable code. |
A PR (#125425) with the tests is merged for this issue. A sincere sorry to @SonOfLilit I added your name in the PR comment but forgot to add it in the commit message. Your observation and fix is greatly appreciated! |
The bug:
@SnoopJ had a snoop and said the change in behavior between 3.10 and 3.11 appears to be caused by #94552, which changes
lineno
for the first opcode in a module from-1
to0
, so we immediately suspect this code inpdb.py
:Indeed, that
frame.f_lineno <= 0
makespdb
not stop for user input when running with an empty module, and removing it doesn't affect behavior for a nonempty module. It was added in 2004 as part of the_wait_for_mainpyfile
feature and wasn't touched since - at the time there must have been some other opcode with index-1
that we don't want to pause on. Honestly, I couldn't figure out why this doesn't manifest in3.10
.Still, removing this clause seems safe as far as I can tell, and fixes the bug. @iritkatriel could I ask you to have a look? You opened the pull request that may have sparked this, and you're the one who inspired me yesterday at Pycon to take an evening and try to fix some
pdb
bugs.