Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdb.run() does not trace destructors of __main__ #77639

Open
xdegaye mannequin opened this issue May 10, 2018 · 2 comments
Open

pdb.run() does not trace destructors of __main__ #77639

xdegaye mannequin opened this issue May 10, 2018 · 2 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@xdegaye
Copy link
Mannequin

xdegaye mannequin commented May 10, 2018

BPO 33458
Nosy @xdegaye

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2018-05-10.20:27:37.753>
labels = ['3.7', '3.8', 'type-bug', 'library']
title = 'pdb.run() does not trace destructors of __main__'
updated_at = <Date 2018-05-10.20:33:13.995>
user = 'https://github.com/xdegaye'

bugs.python.org fields:

activity = <Date 2018-05-10.20:33:13.995>
actor = 'xdegaye'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2018-05-10.20:27:37.753>
creator = 'xdegaye'
dependencies = []
files = []
hgrepos = []
issue_num = 33458
keywords = []
message_count = 2.0
messages = ['316375', '316376']
nosy_count = 1.0
nosy_names = ['xdegaye']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue33458'
versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

@xdegaye
Copy link
Mannequin Author

xdegaye mannequin commented May 10, 2018

This issue is a companion to bpo-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)

@xdegaye xdegaye mannequin added 3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels May 10, 2018
@xdegaye
Copy link
Mannequin Author

xdegaye mannequin commented May 10, 2018

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:

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

0 participants