This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Pdb.set_trace debugging does not end correctly
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder: pdb raises BdbQuit on 'quit' when started with set_trace
View: 16446
Assigned To: Nosy List: georg.brandl, ppperry, r.david.murray, terry.reedy, xdegaye
Priority: normal Keywords:

Created on 2014-07-17 15:52 by ppperry, last changed 2022-04-11 14:58 by admin.

Messages (6)
msg223342 - (view) Author: (ppperry) Date: 2014-07-17 15:52
In IDLE:
   >>>def dodebug():
	    pdb.set_trace()
   >>>dodebug()
   --Return--
   > <pyshell#6>(2)dodebug()->None
   (Pdb) s
   --Return--
   > <pyshell#8>(1)<module>()->None
   (Pdb) s
PDB should exit, but it doesn't
   > c:\python27\lib\idlelib\run.py(308)runcode()
   -> interruptable = False
   (Pdb)s
   > c:\python27\lib\idlelib\run.py(322)runcode()
   -> flush_stdout()
Quitting from this state raises an error:
   (Pdb)q

   Traceback (most recent call last):
   ** IDLE Internal Exception: 
        File "C:\Python27\lib\idlelib\run.py", line 100, in main
           ret = method(*args, **kwargs)
        File "C:\Python27\lib\idlelib\run.py", line 322, in runcode
           flush_stdout()
        File "C:\Python27\lib\idlelib\run.py", line 322, in runcode
           flush_stdout()
        File "C:\Python27\lib\bdb.py", line 49, in trace_dispatch
           return self.dispatch_line(frame)
        File "C:\Python27\lib\bdb.py", line 68, in dispatch_line
           if self.quitting: raise BdbQuit
     BdbQuit
The same example outside of IDLE:
     >>>def dodebug():
	    pdb.set_trace()
     >>>dodebug()
     --Return--
     > <stdin>(1)dodebug()->None
     (Pdb) s
     --Return--
     > <stdin>(1)<module>()->None
     (Pdb) s
     [clean pbd exit]
     >>>
Note: this bug does not occur with pdb.run().
OS: Windows XP
msg223463 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2014-07-19 10:36
Two issues here:
a) in IDLE, on a 'return' debug event in the main module, the step command does not end the debugging session.
b) in IDLE, BdbQuit is raised by the quit command when the debugger is started with pdb.set_trace().

I do not know IDLE, but a) seems closely related to issue 14743: "on terminating, Pdb debugs itself".

As for b) BdbQuit is also raised outside of IDLE (see also issue 16446: "pdb raises BdbQuit on 'quit' when started with set_trace"):

>>> def dodebug():
...   import pdb; pdb.set_trace()
... 
>>> dodebug()
--Return--
> <stdin>(2)dodebug()->None
(Pdb) quit
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in dodebug
  File "/usr/local/lib/python3.5/bdb.py", line 52, in trace_dispatch
    return self.dispatch_return(frame, arg)
  File "/usr/local/lib/python3.5/bdb.py", line 96, in dispatch_return
    if self.quitting: raise BdbQuit
bdb.BdbQuit
msg223482 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-07-19 22:04
With Python 3.4.1, Win 7, there is a detour stepping through displayhook before arriving at the same place with the same result upon quitting. If one does not quit, stepping ends at

> c:\programs\python34\lib\threading.py(235)__enter__()
-> return self._lock.__enter__()
(Pdb) s
--Return--
s <no response>
---------------

With respect to b, the exception, this seems to be a duplicate, and I am inclined to close this issue as such.

With respect to a, not stopping, this is not a bug, at least not one involving Idle. Idle executes code within an exec call within a call of the runcode method of the Executive class. In a similar circumstance, the console interpreter does not stop either. So I have removed Idle from the title and components.

A direct exec is semi-problemmatical. 

>>> import pdb
>>> def do(): pdb.set_trace()
...
>>> exec('do()', locals())
--Return--
> <stdin>(1)do()->None
(Pdb) s
--Return--
> <string>(1)<module>()->None
(Pdb) s
--Return--
> <stdin>(1)<module>()->None
(Pdb) s

# This returns to a '>>>' prompt,

>>> def run(): exec('do()', locals())

# but hitting <return> after this line returns us to the debugger.

--Call--
> c:\programs\python34\lib\encodings\cp437.py(14)decode()
-> def decode(self,input,errors='strict'):
(Pdb)
> c:\programs\python34\lib\encodings\cp437.py(15)decode()
-> return codecs.charmap_decode(input,errors,decoding_table)
(Pdb) q
  File "<stdin>", line 0

    ^
SyntaxError: decoding with 'cp437' codec failed (BdbQuit: )

# Now we are really out.

>>> run()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'run' is not defined

# the def statement did not execute

>>> def run(): exec('do()', globals())
...
>>> run()

# and now the behavior is as reported for Idle

--Return--
> <stdin>(1)do()->None
s

# about 20 steps later, still going.

s
> c:\programs\python34\lib\encodings\cp437.py(19)encode()
-> return codecs.charmap_encode(input,self.errors,encoding_map)[0]
---------------------------------------------

I know very little about the pdb spec and do not know whether the above is a(n unreported) python or pdb bug or not. If any of you think it is, say so. Otherwise this should be closed.
msg223506 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2014-07-20 10:38
> # This returns to a '>>>' prompt,

At the above line in Terry test, the debugger is not terminated and on linux when I type <Ctl-D> at this point I get:

>>>
--Call--
> /home/xavier/etc/.pystartup(21)save_history()
-> def save_history(historyPath=historyPath):
(Pdb)

So this seems to be demonstrating the same problem as a).

The NameError exception (name 'run' is not defined) is caused by the execution of its def statement having been interrupted by the debugger with BdbQuit.

This issue could be kept open so as to include the "exec('do()', locals())" with the test cases when fixing the problem of Pdb termination.
msg273557 - (view) Author: (ppperry) Date: 2016-08-24 13:23
This issue seems to have languished for over two years.
msg273558 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-08-24 13:35
Your point being?

:)  

What needs to happen is for someone to review the issue and figure out if there is anything left to do.  Has termination been fixed?  Has the test case mentioned in the last message been incorporated?
History
Date User Action Args
2022-04-11 14:58:06adminsetgithub: 66196
2016-08-24 13:35:22r.david.murraysetnosy: + r.david.murray
messages: + msg273558
2016-08-24 13:23:30ppperrysetnosy: + ppperry
messages: + msg273557
2014-07-20 10:38:12xdegayesetmessages: + msg223506
2014-07-19 22:04:33terry.reedysetversions: + Python 3.4, Python 3.5
title: Pdb.set_trace debugging does not end correctly in IDLE -> Pdb.set_trace debugging does not end correctly
messages: + msg223482

components: - IDLE
superseder: pdb raises BdbQuit on 'quit' when started with set_trace
stage: resolved
2014-07-19 10:37:00xdegayesetnosy: + xdegaye
messages: + msg223463
2014-07-18 01:40:19ppperrysethgrepos: - hgrepo264
2014-07-18 01:39:50ppperrysetnosy: + georg.brandl, terry.reedy, - ppperry

hgrepos: + hgrepo264
2014-07-17 16:14:23ppperrysettype: behavior
2014-07-17 15:52:11ppperrycreate