2012-01-29 19 views
6

Attualmente sto usando NetBeans IDE con Jython 2.5.1Il debugger Python viene eseguito nei generatori?

Quando il debug il mio progetto passo dopo passo, non appena viene rilevato un iterazione su un generatore, il debugger va dritto fino alla fine del codice. L'output funziona correttamente, ma è impossibile eseguire il debug passo dopo volta che viene raggiunto il primo generatore.

Si tratta di un comportamento standard per il debug di Python in tutti gli IDE Python? Non è possibile eseguire il debug del codice "yield after yield" nello stesso modo in cui possiamo eseguire il debug di VBA per ogni elemento di un ciclo "for" (mi dispiace per la menzione di VBA :)?

Grazie.

EDIT

Senza il generatore

Codice:

def example(n): 
i = 1 
while i <= n: 
    yield i 
    i += 1 

print "hello" 

print "goodbye" 

uscita:

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 

Con il generatore di

Codice:

def example(n): 
    i = 1 
    while i <= n: 
     yield i 
     i += 1 

print "hello" 

for n in example(3): 
    print n 

print "goodbye" 

uscita:

hello 
1 
2 
3 
goodbye 

Debug:

[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 
+0

Invia il tuo codice. Chiarirà la tua domanda. – Blender

risposta

1

Ho appena testato eclissi e verrà eseguito il debug con pydev installato.

+0

Grazie. Appena installato e si comporta come previsto. – StackyAndHutch

+0

non funziona per me con pydev. – laike9m

2

Non uso NetBeans, ma lo standard pdb passa attraverso i generatori. Per esempio:

$ 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 

Se pubblichi qualche codice, potremmo cercare di capire esattamente cosa sta succedendo nel vostro caso.

+0

Grazie per avermi indirizzato al PDB. Davvero potente Ma stavo cercando un debugger grafico integrato per l'IDE (a differenza di WinPDB). – StackyAndHutch

Problemi correlati