diff options
author | Georg Brandl <georg@python.org> | 2010-08-01 08:35:29 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-08-01 08:35:29 (GMT) |
commit | 8f9f466505960a6cf83b58683cbc98e5d4abba7a (patch) | |
tree | 1678339537ee5b53f38ac0ca40e12c5d0e1f7115 /Lib/trace.py | |
parent | 920bc0fd8610bed289ce38a2bf932248a52fcfb6 (diff) | |
download | cpython-8f9f466505960a6cf83b58683cbc98e5d4abba7a.zip cpython-8f9f466505960a6cf83b58683cbc98e5d4abba7a.tar.gz cpython-8f9f466505960a6cf83b58683cbc98e5d4abba7a.tar.bz2 |
#1690103: fix initial namespace for code run with trace.main().
Diffstat (limited to 'Lib/trace.py')
-rw-r--r-- | Lib/trace.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/trace.py b/Lib/trace.py index 077cdc1..236ea49 100644 --- a/Lib/trace.py +++ b/Lib/trace.py @@ -799,7 +799,14 @@ def main(argv=None): try: with open(progname) as fp: code = compile(fp.read(), progname, 'exec') - t.run(code) + # try to emulate __main__ namespace as much as possible + globs = { + '__file__': progname, + '__name__': '__main__', + '__package__': None, + '__cached__': None, + } + t.runctx(code, globs, globs) except IOError as err: _err_exit("Cannot run file %r because: %s" % (sys.argv[0], err)) except SystemExit: |