2012-01-17 4 views
13

프로파일 링하려는 이메일에 app이라는 함수가 있습니다.Python 용 cProfile이 함수 이름을 인식하지 못합니다.

 exec cmd in globals, locals 
    File "<string>", line 1, in <module> 
    NameError: name 'send_email' is not defined 

나는 여기에 놓치고 무엇 :이 그런 짓을 할 때 나는이 관리 명령을 실행하면, 그것은 다음과 같은 오류가 발생, 최대

from django.core.management import BaseCommand 
    import cProfile 


    class Command(BaseCommand): 
     def handle(self, *args, **options): 
      from email.modname import send_email 
      cProfile.run('send_email(user_id=1, city_id=4)') 

불면? cProfile은 문자열 (전역/로컬 네임 스페이스에서 func 이름 찾기)을 어떻게 평가합니까?

답변

22

send_email을 메서드 정의에 가져온 것이 문제입니다.

난 당신이 runctx를 사용하는 것이 좋습니다 :

cProfile.runctx('send_email()', None, locals()) 

the official documentation에서 :

cProfile.runctx(command, globals, locals, filename=None) 

이 기능은 대한 전역과 지역 주민 사전을 공급하는 추가 인수() 실행과 유사 명령 문자열.

+0

감사합니다. Rik, 가장 확실하게 작동했습니다. – Ben

관련 문제