我试图在复杂的
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://code.activestate.com/recipes/577551/,但它们并没有满足我的需求.
编辑
我现在尝试使用Python跟踪模块,将此行添加到Eclipse中的VM Arguements框中:-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
编辑2
看一个更强大的解决方案,但总是运行而不是一个时间点的解决方案,在这里:Finding full pathname in a Python trace
最佳答案 我不知道如何像你想要的那样设置跟踪;我能提供的是,大多数与存储和检索数据有关的有趣调用都通过… / openerp / osv /目录中的osv.py,fields.py和orm.py进行.