classification
Title: pdb.run() does not trace destructors of __main__
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: xdegaye
Priority: normal Keywords:

Created on 2018-05-10 20:27 by xdegaye, last changed 2018-05-10 20:33 by xdegaye.

Messages (2)
msg316375 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2018-05-10 20:27
This issue is a companion to issue 13044.

Running with Python 3.6.5 the following code fails with NameError:

1 class C:
2     def __del__(self):
3         print('deleted')
4
5 c = C()
6 x = 1

$  python -m pdb bar.py
> ./bar.py(1)<module>()
-> class C:
(Pdb) break 6
Breakpoint 1 at ./bar.py:6
(Pdb) continue
> ./bar.py(6)<module>()
-> x = 1
(Pdb) step
--Return--
> ./bar.py(6)<module>()->None
-> x = 1
(Pdb) step
--Return--
> <string>(1)<module>()->None
(Pdb) step
> /usr/lib/python3.6/bdb.py(438)run()
-> self.quitting = True
(Pdb) step
The program finished and will be restarted
Exception ignored in: <bound method C.__del__ of <__main__.C object at 0x7f3fb3485b70>>
Traceback (most recent call last):
  File "./bar.py", line 3, in __del__
    print('deleted')
NameError: name 'print' is not defined
> ./bar.py(1)<module>()
-> class C:
(Pdb)
msg316376 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2018-05-10 20:33
The following patch fixes the problem when applied applied on top of PR 6730:

diff --git a/Lib/bdb.py b/Lib/bdb.py
index c6a10359ac..07231ec588 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -582,7 +582,7 @@ class Bdb:
             cmd = compile(cmd, "<string>", "exec")
         sys.settrace(self.trace_dispatch)
         try:
-            exec(cmd, globals, locals)
+            exec(cmd, dict(globals), dict(locals))
         except BdbQuit:
             pass
         finally:
History
Date User Action Args
2018-05-10 20:33:13xdegayesetmessages: + msg316376
2018-05-10 20:27:37xdegayecreate