Skip to content

Commit 8f570a7

Browse files
committed
1. Add a command line switch to run without the subprocess
2. Remove the shell menu and associated bindings when running without the subprocess. 3. Update the IDLE Help and usage text. 4. Update display_port_binding_error to suggest using -n M PyShell.py M help.txt
1 parent 5db4843 commit 8f570a7

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

Lib/idlelib/PyShell.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def start_subprocess(self):
332332
self.rpcclt = rpc.RPCClient(addr)
333333
break
334334
except socket.error, err:
335-
print>>sys.__stderr__,"Idle socket error: " + err[1]\
335+
print>>sys.__stderr__,"IDLE socket error: " + err[1]\
336336
+ ", retrying..."
337337
else:
338338
display_port_binding_error()
@@ -650,7 +650,6 @@ class PyShell(OutputWindow):
650650
menu_specs = [
651651
("file", "_File"),
652652
("edit", "_Edit"),
653-
("shell", "_Shell"),
654653
("debug", "_Debug"),
655654
("options", "_Options"),
656655
("windows", "_Windows"),
@@ -661,6 +660,8 @@ class PyShell(OutputWindow):
661660
from IdleHistory import History
662661

663662
def __init__(self, flist=None):
663+
if use_subprocess:
664+
self.menu_specs.insert(2, ("shell", "_Shell"))
664665
self.interp = ModifiedInterpreter(self)
665666
if flist is None:
666667
root = Tk()
@@ -686,8 +687,9 @@ def __init__(self, flist=None):
686687
text.bind("<<toggle-debugger>>", self.toggle_debugger)
687688
text.bind("<<open-python-shell>>", self.flist.open_shell)
688689
text.bind("<<toggle-jit-stack-viewer>>", self.toggle_jit_stack_viewer)
689-
text.bind("<<view-restart>>", self.view_restart_mark)
690-
text.bind("<<restart-shell>>", self.restart_shell)
690+
if use_subprocess:
691+
text.bind("<<view-restart>>", self.view_restart_mark)
692+
text.bind("<<restart-shell>>", self.restart_shell)
691693
#
692694
self.save_stdout = sys.stdout
693695
self.save_stderr = sys.stderr
@@ -810,7 +812,7 @@ def short_title(self):
810812
return self.shell_title
811813

812814
COPYRIGHT = \
813-
'Type "copyright", "credits" or "license" for more information.'
815+
'Type "copyright", "credits" or "license()" for more information.'
814816

815817
def begin(self):
816818
self.resetoutput()
@@ -1072,6 +1074,7 @@ def isatty(self):
10721074
idle [-ds] [-t title] - [arg]*
10731075
10741076
-h print this help message and exit
1077+
-n run IDLE without a subprocess (see Help/IDLE Help for details)
10751078
10761079
The following options will override the IDLE 'settings' configuration:
10771080
@@ -1120,6 +1123,7 @@ def isatty(self):
11201123
def main():
11211124
global flist, root, use_subprocess
11221125

1126+
use_subprocess = True
11231127
enable_shell = False
11241128
enable_edit = False
11251129
debug = False
@@ -1131,7 +1135,7 @@ def main():
11311135
except AttributeError:
11321136
sys.ps1 = '>>> '
11331137
try:
1134-
opts, args = getopt.getopt(sys.argv[1:], "c:deihr:st:")
1138+
opts, args = getopt.getopt(sys.argv[1:], "c:deihnr:st:")
11351139
except getopt.error, msg:
11361140
sys.stderr.write("Error: %s\n" % str(msg))
11371141
sys.stderr.write(usage_msg)
@@ -1150,6 +1154,8 @@ def main():
11501154
sys.exit()
11511155
if o == '-i':
11521156
enable_shell = True
1157+
if o == '-n':
1158+
use_subprocess = False
11531159
if o == '-r':
11541160
script = a
11551161
if os.path.isfile(script):
@@ -1167,9 +1173,6 @@ def main():
11671173
if args and args[0] == '-':
11681174
cmd = sys.stdin.read()
11691175
enable_shell = True
1170-
1171-
use_subprocess = True
1172-
11731176
# process sys.argv and sys.path:
11741177
for i in range(len(sys.path)):
11751178
sys.path[i] = os.path.abspath(sys.path[i])
@@ -1202,7 +1205,6 @@ def main():
12021205
fixwordbreaks(root)
12031206
root.withdraw()
12041207
flist = PyShellFileList(root)
1205-
12061208
if enable_edit:
12071209
if not (cmd or script):
12081210
for filename in args:
@@ -1239,19 +1241,19 @@ def main():
12391241

12401242
def display_port_binding_error():
12411243
print """\
1242-
IDLE cannot run.
1244+
\nIDLE cannot run.
12431245
1244-
IDLE needs to use a specific TCP/IP port (8833) in order to execute and
1245-
debug programs. IDLE is unable to bind to this port, and so cannot
1246-
start. Here are some possible causes of this problem:
1246+
IDLE needs to use a specific TCP/IP port (8833) in order to communicate with
1247+
its Python execution server. IDLE is unable to bind to this port, and so
1248+
cannot start. Here are some possible causes of this problem:
12471249
12481250
1. TCP/IP networking is not installed or not working on this computer
1249-
2. Another program is running that uses this port
1251+
2. Another program (another IDLE?) is running that uses this port
12501252
3. Personal firewall software is preventing IDLE from using this port
12511253
1252-
IDLE makes and accepts connections only with this computer, and does not
1253-
communicate over the internet in any way. Its use of port 8833 should not
1254-
be a security risk on a single-user machine.
1254+
Run IDLE with the -n command line switch to start without a subprocess
1255+
and refer to Help/IDLE Help "Running without a subprocess" for further
1256+
details.
12551257
"""
12561258

12571259
if __name__ == "__main__":

Lib/idlelib/help.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,16 @@ Other preferences:
191191
Command line usage:
192192

193193
Enter idle -h at the command prompt to get a usage message.
194+
195+
Running without a subprocess:
196+
197+
If IDLE is started with the -n command line switch it will run in a
198+
single process and will not create the subprocess which runs the RPC
199+
Python execution server. This can be useful if Python cannot create
200+
the subprocess or the RPC socket interface on your platform. However,
201+
in this mode user code is not isolated from IDLE itself. Also, the
202+
environment is not restarted when Run/Run Module (F5) is selected. If
203+
your code has been modified, you must reload() the affected modules and
204+
re-import any specific items (e.g. from foo import baz) if the changes
205+
are to take effect. For these reasons, it is preferable to run IDLE
206+
with the default subprocess if at all possible.

0 commit comments

Comments
 (0)