2012-07-03 10 views
5

Stavo cercando di eseguire un test delle prestazioni del mio codice utilizzando cProfile, ma purtroppo non importa quanto ho provato che cProfile ha rifiutato di funzionare correttamente. Ecco quello che ho fatto:python - cProfile non è in esecuzione

import cProfile 
cProfile.run('addNum()') # addNum() is a very simple function that adds a bunch of 
          # numbers into a dictionary 

ed ecco quello che ho ottenuto:

Traceback (most recent call last): 
File "C:\Program Files\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 1, in <module> 
# Used internally for debug sandbox under external interpreter 
File "C:\Python27\Lib\cProfile.py", line 36, in run 
result = prof.print_stats(sort) 
File "C:\Python27\Lib\cProfile.py", line 81, in print_stats 
pstats.Stats(self).strip_dirs().sort_stats(sort).print_stats() 
File "C:\Python27\Lib\pstats.py", line 81, in __init__ 
self.init(arg) 
File "C:\Python27\Lib\pstats.py", line 95, in init 
self.load_stats(arg) 
File "C:\Python27\Lib\pstats.py", line 124, in load_stats 
self.__class__, arg) 
TypeError: Cannot create or construct a <class pstats.Stats at 0x01AE9CA8> object from '<cProfile.Profile object at 0x01ACC470>'' 

Qualcuno può aiutarmi il debug di questo, e si spera di fornire una soluzione?

Sto eseguendo Python 2.7.3 su Wing IDE 101 ver4.1.

Grazie !!!

risposta

3

Questo sembra un problema con il modulo pStats e non con il cProfile.

si può provare a fare

import pstats 

Se questo dice che non può importare pstats, quindi provare a installare di nuovo il python-profiler. Viene fornito con Python stesso ma potrebbe essere incasinato nel tuo caso SE pstats non è lì.

È un semplice apt-get su linux, quindi presumo che Windows abbia un binario separato anche per Python-Profiler.

Spero che questo aiuti!

+0

Ho provato a importare pstats, ma ha comunque riportato lo stesso errore. = [ – turtlesoup

+1

No, intendevo solo provare a scrivere import pstats in una shell. Basta controllare se è lì o no, e se è lì, allora si ottengono altri errori o no. Se importa con successo, allora dovresti vedere se il modulo non è cattivo o qualcosa del genere. Prova alcune delle funzioni menzionate qui http://docs.python.org/library/profile.html per pstats in un file separato (non nel tuo codice principale, solo per verificare se pstats funziona correttamente). –

Problemi correlati