Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDB.run - restarting a pdb session

Tags:

python

pdb

I'm relatively new to python and pdb, but I have a lot of experience with gdb.

My problem is that if I set a number of breakpoints in my code at some point I will want to change something and re-run my debug session retaining these break points. However entering "run" in my pdb session cases my session to terminate with the following output

(Pdb) run
  Traceback (most recent call last):
  File "/usr/lib64/python2.6/runpy.py", line 122, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib64/python2.6/runpy.py", line 34, in _run_code
    exec code in run_globals
  File "/usr/lib64/python2.6/pdb.py", line 1319, in <module>
    pdb.main()
  File "/usr/lib64/python2.6/pdb.py", line 1312, in main
    pdb.interaction(None, t)
  File "/usr/lib64/python2.6/pdb.py", line 198, in interaction
    self.cmdloop()
  File "/usr/lib64/python2.6/cmd.py", line 142, in cmdloop
    stop = self.onecmd(line)
  File "/usr/lib64/python2.6/pdb.py", line 267, in onecmd
    return cmd.Cmd.onecmd(self, line)
  File "/usr/lib64/python2.6/cmd.py", line 219, in onecmd
    return func(arg)
  File "/usr/lib64/python2.6/pdb.py", line 661, in do_run
    raise Restart
pdb.Restart
]$

I've tried this on two independent linux platforms and had the same result but I cannot find any corrections in the documentation.

like image 519
dmon Avatar asked Oct 08 '12 14:10

dmon


1 Answers

Here is my file test.py:

import pdb
pdb.set_trace()
print('1 line')

I get the same error when I using command 'python3 test.py':

> /home/wangpq/program_note/test.py(3)<module>()
-> print('1 line')
(Pdb) run
Traceback (most recent call last):
  File "program_note/test.py", line 3, in <module>
    print('1 line')
  File "program_note/test.py", line 3, in <module>
    print('1 line')
  File "/usr/lib/python3.5/bdb.py", line 48, in trace_dispatch
    return self.dispatch_line(frame)
  File "/usr/lib/python3.5/bdb.py", line 66, in dispatch_line
    self.user_line(frame)
  File "/usr/lib/python3.5/pdb.py", line 259, in user_line
    self.interaction(frame, None)
  File "/usr/lib/python3.5/pdb.py", line 346, in interaction
    self._cmdloop()
  File "/usr/lib/python3.5/pdb.py", line 319, in _cmdloop
    self.cmdloop()
  File "/usr/lib/python3.5/cmd.py", line 138, in cmdloop
    stop = self.onecmd(line)
  File "/usr/lib/python3.5/pdb.py", line 412, in onecmd
    return cmd.Cmd.onecmd(self, line)
  File "/usr/lib/python3.5/cmd.py", line 217, in onecmd
    return func(arg)
  File "/usr/lib/python3.5/pdb.py", line 1022, in do_run
    raise Restart
pdb.Restart

Then I use command 'python3 -m pdb test.py'

wangpq@wangpq:~$ python3 -m pdb program_note/test.py
> /home/wangpq/program_note/test.py(1)<module>()
-> import pdb
(Pdb) restart
Restarting program_note/test.py with arguments:
    program_note/test.py
> /home/wangpq/program_note/test.py(1)<module>()
-> import pdb
(Pdb) 

It works. So far, I am not sure why this happens.

like image 181
Eden Wang Avatar answered Sep 29 '22 05:09

Eden Wang