Does the Python debugger work in generators?

I am currently using NetBeans IDE with Jython 2.5.1

When debugging my project step by step, as soon as iterating over the generator occurs, the debugger goes right to the end of the code. The output works fine, but phased debugging cannot be performed after the first generator is executed.

Is this the standard behavior for debugging Python in an entire Python environment? Is it impossible to debug the "yield after yield" code in the same way that we can debug VBA for each element of the "for" loop (sorry for mentioning VBA :)?

Thanks.

EDIT

Without generator

the code:

def example(n): i = 1 while i <= n: yield i i += 1 print "hello" print "goodbye" 

Conclusion:

 hello goodbye 

Debugging:

 [LOG]PythonDebugger : overall Starting [LOG]PythonDebugger.taskStarted : I am Starting a new Debugging Session ... [LOG]This window is an interactive debugging context aware Python Shell [LOG]where you can enter python console commands while debugging (...) >>>[stdout:]hello >>>[stdout:]goodbye Debug session normal end 

With generator

the code:

 def example(n): i = 1 while i <= n: yield i i += 1 print "hello" for n in example(3): print n print "goodbye" 

Conclusion:

 hello 1 2 3 goodbye 

Debugging:

 [LOG]PythonDebugger : overall Starting [LOG]PythonDebugger.taskStarted : I am Starting a new Debugging Session ... [LOG]This window is an interactive debugging context aware Python Shell [LOG]where you can enter python console commands while debugging (...) >>>[stdout:]hello >>>None['GeneratorExit deamon ended '] Debug session normal end 
+6
source share
2 answers

I just tested eclipse and debugged with pydev .

+1
source

I do not use NetBeans, but pdb at least takes a step through the generators. For instance:

 $ cat test.py def the_generator(): for i in xrange(10): yield i for x in the_generator(): print x $ python -mpdb test.py > test.py(1)<module>() -> def the_generator(): (Pdb) n > test.py(5)<module>() -> for x in the_generator(): (Pdb) s --Call-- > test.py(1)the_generator() -> def the_generator(): (Pdb) n > test.py(2)the_generator() -> for i in xrange(10): (Pdb) n > test.py(3)the_generator() -> yield i (Pdb) n --Return-- > test.py(3)the_generator()->0 -> yield i (Pdb) n > test.py(6)<module>() -> print x (Pdb) n 0 

If you post some code, we can try to figure out what happens in your case.

+2
source

Source: https://habr.com/ru/post/907136/


All Articles