Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d694c1f

Browse files
committed
Reset the Python execution server environment to its initial value prior
to executing Run/F5 from an EditorWindow. M ScriptBinding.py : add call to clear_the_environment() M run.py : implemented Executive.clear_the_environment()
1 parent 139bccb commit d694c1f

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

Lib/idlelib/ScriptBinding.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,19 @@ def run_script_event(self, event):
144144
filename = self.getfilename()
145145
if not filename:
146146
return
147-
148147
flist = self.editwin.flist
149148
shell = flist.open_shell()
150149
interp = shell.interp
150+
# clear the subprocess environment before every Run/F5 invocation
151+
interp.rpcclt.remotecall("exec", "clear_the_environment", (), {})
151152
# XXX Too often this discards arguments the user just set...
152153
interp.runcommand("""if 1:
153154
_filename = %s
154155
import sys as _sys
155156
from os.path import basename as _basename
156157
if (not _sys.argv or
157158
_basename(_sys.argv[0]) != _basename(_filename)):
159+
# XXX 25 July 2002 KBK should this be sys.argv not _sys.argv?
158160
_sys.argv = [_filename]
159161
del _filename, _sys, _basename
160162
\n""" % `filename`)

Lib/idlelib/run.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
import time
33
import socket
4+
import __main__
45
import rpc
56

67
def main():
@@ -55,11 +56,18 @@ class Executive:
5556

5657
def __init__(self, rpchandler):
5758
self.rpchandler = rpchandler
58-
import __main__
59-
self.locals = __main__.__dict__
59+
self.base_env_keys = __main__.__dict__.keys()
6060

6161
def runcode(self, code):
62-
exec code in self.locals
62+
exec code in __main__.__dict__
63+
64+
def clear_the_environment(self):
65+
global __main__
66+
env = __main__.__dict__
67+
for key in env.keys():
68+
if key not in self.base_env_keys:
69+
del env[key]
70+
env['__doc__'] = None
6371

6472
def start_the_debugger(self, gui_adap_oid):
6573
import RemoteDebugger

0 commit comments

Comments
 (0)