python - 从代码中的一个点跟踪所有语句

标签 python eclipse odoo

我正在尝试跟踪复杂 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

最佳答案

我不知道如何像您想要的那样设置跟踪;我所能提供的是,大多数与数据存储和检索相关的有趣调用都通过 osv.pyfields.pyorm.py .../openerp/osv/ 目录中。

关于python - 从代码中的一个点跟踪所有语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20706614/

相关文章:

python - django 的分页在 django View 中是如何工作的

java - 从 Eclipse 将带有库的项目导出到可运行的 jar

xml - Eclipse 中缺少 xml 配置选项卡?

javascript - HTML - XML - 跳转到另一个选项卡/页面元素

css - 在 Odoo10 中选中复选框时,复选框轮廓消失

python 在使用 ssh 时找不到模块

python - 在保留注释的同时修改 python AST

java - 如何将Java项目facet设置为12?

email - 恢复管理员密码和电子邮件 Odoo 服务器

Python Pandas Lambda 行重命名匿名函数?