This Question have no Text answers yet!

Python pdb debugger, doesn't exit on q in some cases

Question!

I'm familiar with the fact that debuggers don't perfectly emulate the normal execution environment, and I've seen cases where pdb gets tracebacks after a program exits normally or gets multiple tracebacks after some kinds of errors. I'm mentioning this example because I produced it with a very simple program, and I think I understand (somewhat) why it happened.

When I run the following program, the assert fails and pdb enters post-mortem mode. When I then type q, it cannot exit until the file f is closed. Instead, it prepares to restart and I have to type q a second time.

""" t1.py test pdb gets traceback on normal exit """

with open('t1.py') as f:
    f.readline()
    assert(False)

Here is the output:

 /tmp/tp $ python3 -m pdb t1.py 
> /tmp/tp/t1.py(1)<module>()
-> """ t1.py test pdb gets traceback on normal exit """
(Pdb) c
Traceback (most recent call last):
  File "/usr/lib/python3.4/pdb.py", line 1661, in main
    pdb._runscript(mainpyfile)
  File "/usr/lib/python3.4/pdb.py", line 1542, in _runscript
    self.run(statement)
  File "/usr/lib/python3.4/bdb.py", line 431, in run
    exec(cmd, globals, locals)
  File "<string>", line 1, in <module>
  File "/tmp/tp/t1.py", line 1, in <module>
    """ t1.py test pdb gets traceback on normal exit """
AssertionError
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /tmp/tp/t1.py(1)<module>()
-> """ t1.py test pdb gets traceback on normal exit """
(Pdb) q
Post mortem debugger finished. The t1.py will be restarted
> /tmp/tp/t1.py(1)<module>()
-> """ t1.py test pdb gets traceback on normal exit """
(Pdb) q
 /tmp/tp $ 

Is this as predictable as it appears to be? Am I right in thinking it's due to the end callbacks?

By : bitchaser


Video about Python pdb debugger, doesn't exit on q in some cases