5

When in the Python debugger (pdb) I want to step over a yield statement, but hitting (n) for next brings me to the destination of the yield i.e. the consumer of the generator. I want to go to the next line that is executed within the generator. Is there any way to do this?

I'm using Python 2.6

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
EoghanM
  • 25,161
  • 23
  • 90
  • 123
  • 1
    That definitely sounds like what next should be doing. (From the perspective of the generator, `yield` is a function call and should be jumped over by `next`.) This sounds like a debugger bug; you might want to see if it's been reported at http://bugs.python.org/. – Glenn Maynard May 23 '10 at 19:56
  • 3
    Although I can see why the behaviour asked for here might be desirable, I can see an equally good argument that taking a single step in a debugger shouldn't run the risk of jumping out of the debugging loop and running indefinitely. (eg. if the generator is never called again). It sounds like a job for a breakpoint to me. (Or a new debugger command.) – Kylotan May 24 '10 at 10:05
  • Possible duplicate of [How to make yield work in debug mode?](https://stackoverflow.com/questions/47380092/how-to-make-yield-work-in-debug-mode) – Gilles 'SO- stop being evil' Apr 15 '19 at 14:35

2 Answers2

-2

If your debugger allows you to use breakpoints and change variable values when you're there, it's as simple as [in pseudo code]

Set Boolean yieldValue to true;
[breakpoint after that line is executed, you can set yieldValue to false here]
if yieldValue, yield value;

in other words:

bool yieldValue = true;
[breakpoint here]
if(yieldValue) yield value;

Note that you usually can't stick a breakpoint on an empty line. You'll have to stick it before the if statement, though.

Warty
  • 7,237
  • 1
  • 31
  • 49
-2

In debuggers, generally you want to "step" (s) into a function in this case, rather than "next" (n).

"Next" executes the next line in the scope you're looking at; "step" brings you into the next scope down, the generator in this case, which sounds like what you want to do.

Vicki Laidler
  • 3,415
  • 1
  • 20
  • 17
  • No, he's saying that *within the generator*, he wants to step over a yield and land on the line following it, which is exactly what "next" should be doing. ("1 comment per 15 seconds, timer reset"? Ugh, whoever thought that was a good idea needs to be shot...) – Glenn Maynard May 23 '10 at 19:58