Home > Software design >  Odoo.sh Editor on Jupyter : pdb.set_trace raises BdbQuit Error
Odoo.sh Editor on Jupyter : pdb.set_trace raises BdbQuit Error

Time:02-13

Using my odoo.sh project (v13.0.2) > EDITOR-Tab , which redirects me to mywebsite.odoo.com/odoo-sh/editor/lab, when i want to debug using import pdb; pdb.set_trace(), it raises a BdbQuit Error :

  File "/usr/lib/python3.6/bdb.py", line 113, in 
  dispatch_exception
    if self.quitting: raise BdbQuit

In the past versions : v13.0.1.xxx, i could use pdb.set_trace() to debug my python code. How to solve this issue ?

CodePudding user response:

Using this post How to debug python CLI that takes stdin?, I have managed it this way :

  1. in Odoo.sh>EDITOR (Jupyter Lab): Open a first Terminal and create these two fifos which will be used as stdin/stdout to use pdb :

     mkfifo fifo_stdin
    
     mkfifo fifo_stdout
    
     cat fifo_stdout & cat > fifo_stdin
    

...which makes appear a prompt cursor. Keep this Terminal Tab opened.

  1. Write these 2 lines at the top of the Python script to be debugged :

     import pdb
     mypdb=pdb.Pdb(stdin=open('fifo_stdin','r'), stdout=open('fifo_stdout','w'))
    
  2. In this Python script, call set_trace() on your customized mypdb using the 2 fifos

    def _get_total_amount(self):     
       total_amount = sum(self._get_base_order_lines(program).mapped('price_total')) 
       mypdb.set_trace()  
       return total_amount
    
  3. Open a second Terminal to launch your Odoo application :

    odoo-bin -u sale_coupon --stop-after-init
    

...and wait till all modules get loaded

  1. Switch to the first Terminal window (fifo)

  2. In another Webbrowser-tab : Browse on your Odoo App / Website to trigger the function where you put your set_trace()

  3. Go to the first Terminal and input function variables to be observed :

      total_amount
      1480.0
      (Pdb) 
    
  4. Go further in your app process (next breakpoint if any) using "continue" and abort debugging using "quit"

      (Pdb) continue
      (Pdb) quit
    
  5. Exit pdb using the keyboard combination : Ctrl D

  6. Odoo could remain hanging, which required to comment the pdb-lines in the python script, close Terminal windows and relaunched your Odoo-App :

    odoo-bin -u sale_coupon --stop-after-init

  • Related