Skip to content

Commit

Permalink
pprofile: Add missing __builtins__ global when running a file.
Browse files Browse the repository at this point in the history
  • Loading branch information
vpelletier committed Jul 1, 2020
1 parent 6a9d7a4 commit adf1881
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ script:
- pprofile --include demo demo/twocalls.py
- pprofile --include demo demo/twocalls2.py
- pprofile --include demo demo/the_main.py
- pprofile --include demo demo/module_globals.py
5 changes: 5 additions & 0 deletions demo/module_globals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# All these globals must be defined.
__builtins__
__file__
__name__
__package__
1 change: 1 addition & 0 deletions pprofile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ def runfile(self, fd, argv, fd_name='<unknown>', compile_flags=0,
code_module = type(original_main)('__main__', docstring)
ctx_globals = code_module.__dict__
ctx_globals.update(globals)
ctx_globals['__builtins__'] = __builtins__
ctx_globals['__file__'] = fd_name
ctx_globals['__name__'] = '__main__'
ctx_globals['__package__'] = None
Expand Down

0 comments on commit adf1881

Please sign in to comment.