Let's say I have a Python script yieldtest.py
using a generator function:
def yieldfunc():
yield 2
yield 4
yield 8
yield 16
def main():
nums = yieldfunc()
for n in nums:
print(n)
if __name__ == "__main__":
main()
It works fine. But let's say something went wrong, so I want to debug it. So I type:
$ python -m pdb yieldtest.py
Then when I get to the line nums = yieldfunc()
, I type s
and hit Enter, which I would expect to bring me inside yieldfunc()
so I can see what's occurring under the hood. That's not what happens, though. Instead it brings me to the next line in def main()
:
> /...path/yieldtest.py(8)main()
-> nums = yieldfunc()
(Pdb) s
> /...path/yieldtest.py(9)main()
-> for n in nums:
(Pdb)
This means that I have to essentially black-box test all of my functions which use yield
.
Is there any solution to this using the PDB debugger that will allow me to step into a generator function?