我正在尝试跟踪复杂的 Python 应用程序(OpenERP)中的调用和代码流。更复杂的是,OpenERP 有自己的继承系统,与普通的 Python 继承并行。
我想做的是获得执行代码的完整列表,以及模块/函数名称。
我尝试过 Eclipse 调试器,并且我了解 pdb 的工作方式大致相同,但单步执行过程花费的时间太长。
我也尝试过使用跟踪启动应用程序,但在我想要跟踪的点之前得到了太多不必要的跟踪。我确实尝试排除模块和目录,但没有多大帮助。
python -m trace -t --ignore-dir=/home/sean/unifield/utp729b/unifield-server --ignore-dir=/home/sean/unifield/utp729b/unifield-web --ignore-module=SocketServer,socket,threading,tiny_socket,__init__,trace,netsvc,posixpath,zipfile,config,genericpath,orm openerp-server.py --db_host=localhost --db_port=5432 --db_user=openerp --db_password=xxxx --addons-path=/home/sean/unifield/utp729b/unifield-addons,/home/sean/unifield/utp729b/sync_module_prod,/home/sean/unifield/utp729b/unifield-wm > /home/sean/trace.log
我想做的事是在代码中设置断点,但不是单步执行代码,而是开始记录到文件。
我还尝试使用装饰器,并附有示例http://eli.thegreenplace.net/2012/08/22/easy-tracing-of-nested-function-calls-in-python/ http://eli.thegreenplace.net/2012/08/22/easy-tracing-of-nested-function-calls-in-python/ and http://code.activestate.com/recipes/577551/ http://code.activestate.com/recipes/577551/,但他们没有满足我的需求。
EDIT
我现在尝试使用 Python 跟踪模块,将这一行添加到虚拟机参数Eclipse 中的框:-m trace -t --trace
这开始产生我正在寻找的内容,逐行跟踪,但是当 OpenERP 完全启动时就停止工作。请参阅下面控制台输出的(冗长)摘录。
pydevd_tracing.py(46): if TracingFunctionHolder._warn:
pydevd_tracing.py(62): TracingFunctionHolder._original_tracing(tracing_func)
pydevd_tracing.py(69): TracingFunctionHolder._warn = True
pydevd_tracing.py(71): TracingFunctionHolder._lock.release()
pydevd.py(1075): try:
pydevd.py(1077): threading.settrace(self.trace_dispatch) # for all future threads
pydevd.py(1081): try:
pydevd.py(1082): thread.start_new_thread = pydev_start_new_thread
pydevd.py(1083): thread.start_new = pydev_start_new_thread
pydevd.py(1087): while not self.readyToRun:
pydevd.py(1088): time.sleep(0.1) # busy wait until we receive run command
pydevd.py(1087): while not self.readyToRun:
pydevd.py(1088): time.sleep(0.1) # busy wait until we receive run command
pydevd.py(1087): while not self.readyToRun:
pydevd.py(1088): time.sleep(0.1) # busy wait until we receive run command
pydevd.py(1087): while not self.readyToRun:
pydevd.py(1088): time.sleep(0.1) # busy wait until we receive run command
pydevd.py(1087): while not self.readyToRun:
pydevd.py(1088): time.sleep(0.1) # busy wait until we receive run command
pydevd.py(1087): while not self.readyToRun:
pydevd.py(1088): time.sleep(0.1) # busy wait until we receive run command
pydevd.py(1087): while not self.readyToRun:
pydevd.py(1090): PyDBCommandThread(debugger).start()
pydevd.py(1092): pydev_imports.execfile(file, globals, locals) #execute the script
[2014-01-05 18:33:51,992][?] INFO:server:OpenERP version - 6.0.3
[2014-01-05 18:33:51,993][?] INFO:server:addons_path - /home/sean/unifield/utp729b/unifield-addons,/home/sean/unifield/utp729b/sync_module_prod,/home/sean/unifield/utp729b/unifield-wm
[2014-01-05 18:33:51,993][?] INFO:server:database hostname - localhost
[2014-01-05 18:33:51,993][?] INFO:server:database port - 5432
[2014-01-05 18:33:51,994][?] INFO:server:database user - openerp
[2014-01-05 18:33:51,994][?] INFO:server:initialising distributed objects services
[2014-01-05 18:33:52,316][?] INFO:web-services:starting HTTP service at 0.0.0.0 port 8069
[2014-01-05 18:33:52,316][?] INFO:web-services:starting HTTPS service at 0.0.0.0 port 8071
[2014-01-05 18:33:52,317][?] INFO:web-services:Registered XML-RPC over HTTP
[2014-01-05 18:33:52,318][?] INFO:web-services:starting NET-RPC service at 0.0.0.0 port 8070
[2014-01-05 18:33:52,318][?] INFO:server:Starting 3 services
[2014-01-05 18:33:52,319][?] INFO:server:OpenERP server is running, waiting for connections...
[2014-01-05 18:34:02,476][utp729b_HQ_01] INFO:init:module base: loading objects
[2014-01-05 18:34:02,478][utp729b_HQ_01] INFO:init:module base: registering objects
[2014-01-05 18:34:03,060][utp729b_HQ_01] INFO:init:module base: loading objects
[2014-01-05 18:34:03,185][utp729b_HQ_01] INFO:init:module msf_button_access_rights: loading objects
[2014-01-05 18:34:03,186][utp729b_HQ_01] INFO:init:module msf_button_access_rights: registering objects
[2014-01-05 18:34:03,203][utp729b_HQ_01] INFO:init:module spreadsheet_xml: loading objects
EDIT 2
查看更强大的解决方案,但该解决方案始终运行而不是某个时间点,请参见此处:在 Python 跟踪中查找完整路径名 https://stackoverflow.com/questions/20947780/finding-full-pathname-in-a-python-trace