Python pdb debugger gets confused when Python method called after a tree_but_open event defined in XML

[亡魂溺海] 提交于 2019-12-08 11:24:16

问题


I am in the process of debugging something in OpenERP using Python 2.7.3. The debugger seems to get out of sync with the code when stepping through with the Next (n) command. When you type a debugger command such as print variable, it may give a different answer each time you do this. It also appears to skip backwards when stepping through the code. See Code and output below.

I believe the problem may be related to the way OpenERP calls my method through a Python exec() statement by reading the code field in the OpenERP XML below. Is possible that calling Python code constructed dynamically and called via exec() is confusing the pdb debugger? When I call the function from a Button rather than a a tree_but_open event the debugger steps through the code fine.

If this is the case is there a work around?

CODE is called via this OpenERP action below:

<record id="action_wash_st_method1" model="ir.actions.server">
            <field name="type">ir.actions.server</field>
            <field name="condition">True</field>
            <field name="state">code</field>
            <field name="model_id" ref="model_view_tree_display_address_list"/>
            <field eval="5" name="sequence"/>
            <field name="code">
action = self.view_calc_sales_tax(cr, uid, context)
</field>
           <field name="name">wash state action request</field>
</record>

 <record model="ir.values" id="action_wash_st_tax_trigger_method1" >
            <field name="key2" eval="'tree_but_open'" />
            <field name="model" eval="'view.tree.display.address.list'" />
            <field name="name">Method1 Wash State</field>
            <field name="value" eval="'ir.actions.server,%d'%action_wash_st_method1"/>
            <field name="object" eval="True" />
 </record>

PDB/CODE OUTPUT (Notice that I have to type "ids" twice to get it to print the value):

-> ctx["local_rate"] = res1["local_rate"]
(Pdb) n
> /home/glenn2/openerp6.1/addons/6.1/wash_tax2/wash_tax.py(169)view_calc_sales_tax()
-> ctx["code"] = res1["code"]
(Pdb) n
> /home/glenn2/openerp6.1/addons/6.1/wash_tax2/wash_tax.py(172)view_calc_sales_tax()
-> ids = [3333,4444,9999]
(Pdb) n
(Pdb) > /home/glenn2/openerp6.1/addons/6.1/wash_tax2/wash_tax.py(173)view_calc_sales_tax()
-> self.pool.get('account.invoice').button_reset_taxes (cr,uid, ids, ctx)
ids
*** NameError: name 'ids' is not defined
(Pdb) ids
[3333, 4444, 9999]
(Pdb)

Additional information:

I think it has to do with the debugger having trouble with multiple threads. The problem starts happening after calls to __bootstrap_inner() in Pythons threading library. Does anyone know if it is possible to enable the Python debugger for multiple threads:

(Pdb) > /home/glenn2/usr/local/lib/python2.7/threading.py(526)__bootstrap()
-> self.__bootstrap_inner()

>(Pdb)  /home/glenn2/usr/local/lib/python2.7/threading.py(526)__bootstrap()->None
-> self.__bootstrap_inner()
self
(Pdb) <Thread(Thread-35, initial)>
self
<Thread(Thread-34, stopped 47994097374976)>
(Pdb) self
(Pdb) <Thread(Thread-34, stopped 47994097374976)>
self
(Pdb) <Thread(Thread-35, initial)>
self
(Pdb) <Thread(Thread-34, stopped 47994097374976)>
self
(Pdb) <Thread(Thread-35, initial)>
self
(Pdb) <Thread(Thread-34, stopped 47994097374976)>
self
<Thread(Thread-35, initial)>
(Pdb) self
(Pdb) <Thread(Thread-34, stopped 47994097374976)>

回答1:


I've used the Python debugger in Eclipse and PyDev for multiple threads. I initially ran into some problems, but the PyDev team patched them up. It might be worth trying PyDev to see if your problem still occurs.

I posted a few more details about setting up OpenERP under PyDev in another answer.



来源:https://stackoverflow.com/questions/11821565/python-pdb-debugger-gets-confused-when-python-method-called-after-a-tree-but-ope

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!