简体   繁体   中英

cProfile for non terminating python program

I have a non terminating python program that I debug with

import faulthandler
faulthandler.dump_traceback_later(480,exit=True)
call_very_complicated_python_code()

I want to profile it to gain better understanding which parts are stuck:

$ python -m cProfile -o program.prof my_program.py my_input.txt
  • Does faulhandler mechanism interfere with the profiling?
  • program.prof is not always generated.
  • Any way to solve this?

I've not used faulthandler , but sounds like the wrong tool for the job anyway. If you code never ends or errors, where is the traceback coming from?

Profiling is used to measure the speed of your code. If you want to understand the code, I'd suggest debugging it with something like pdb.

Add import pdb up the top of your module(s).

In areas you'd like to stop and inspect add: pdb.set_trace()

Perhaps you have some recursion or loop which is never competed?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM