forked from fedora-python/python26
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuse-ephemeral-port-for-IDLE.patch
128 lines (118 loc) · 5.78 KB
/
use-ephemeral-port-for-IDLE.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
diff -up Python-2.4.3/Lib/idlelib/NEWS.txt.idle-ports Python-2.4.3/Lib/idlelib/NEWS.txt
diff -up Python-2.4.3/Lib/idlelib/PyShell.py.idle-ports Python-2.4.3/Lib/idlelib/PyShell.py
--- Python-2.4.3/Lib/idlelib/PyShell.py.idle-ports 2004-12-22 23:32:25.000000000 -0500
+++ Python-2.4.3/Lib/idlelib/PyShell.py 2010-09-08 16:22:36.000000000 -0400
@@ -37,7 +37,8 @@ import Debugger
import RemoteDebugger
IDENTCHARS = string.ascii_letters + string.digits + "_"
-LOCALHOST = '127.0.0.1'
+HOST = '127.0.0.1' # python execution server on localhost loopback
+PORT = 0 # someday pass in host, port for remote debug capability
try:
from signal import SIGTERM
@@ -339,17 +340,21 @@ class ModifiedInterpreter(InteractiveInt
InteractiveInterpreter.__init__(self, locals=locals)
self.save_warnings_filters = None
self.restarting = False
- self.subprocess_arglist = self.build_subprocess_arglist()
+ self.subprocess_arglist = None
+ self.port = PORT
- port = 8833
rpcclt = None
rpcpid = None
def spawn_subprocess(self):
+ if self.subprocess_arglist == None:
+ self.subprocess_arglist = self.build_subprocess_arglist()
args = self.subprocess_arglist
self.rpcpid = os.spawnv(os.P_NOWAIT, sys.executable, args)
def build_subprocess_arglist(self):
+ assert (self.port!=0), (
+ "Socket should have been assigned a port number.")
w = ['-W' + s for s in sys.warnoptions]
# Maybe IDLE is installed and is being accessed via sys.path,
# or maybe it's not installed and the idle.py script is being
@@ -368,11 +373,8 @@ class ModifiedInterpreter(InteractiveInt
return [decorated_exec] + w + ["-c", command, str(self.port)]
def start_subprocess(self):
- # spawning first avoids passing a listening socket to the subprocess
- self.spawn_subprocess()
- #time.sleep(20) # test to simulate GUI not accepting connection
- addr = (LOCALHOST, self.port)
- # Idle starts listening for connection on localhost
+ addr = (HOST, self.port)
+ # GUI makes several attempts to acquire socket, listens for connection
for i in range(3):
time.sleep(i)
try:
@@ -383,6 +385,18 @@ class ModifiedInterpreter(InteractiveInt
else:
self.display_port_binding_error()
return None
+ # if PORT was 0, system will assign an 'ephemeral' port. Find it out:
+ self.port = self.rpcclt.listening_sock.getsockname()[1]
+ # if PORT was not 0, probably working with a remote execution server
+ if PORT != 0:
+ # To allow reconnection within the 2MSL wait (cf. Stevens TCP
+ # V1, 18.6), set SO_REUSEADDR. Note that this can be problematic
+ # on Windows since the implementation allows two active sockets on
+ # the same address!
+ self.rpcclt.listening_sock.setsockopt(socket.SOL_SOCKET,
+ socket.SO_REUSEADDR, 1)
+ self.spawn_subprocess()
+ #time.sleep(20) # test to simulate GUI not accepting connection
# Accept the connection from the Python execution server
self.rpcclt.listening_sock.settimeout(10)
try:
@@ -732,13 +746,12 @@ class ModifiedInterpreter(InteractiveInt
def display_port_binding_error(self):
tkMessageBox.showerror(
"Port Binding Error",
- "IDLE can't bind TCP/IP port 8833, which is necessary to "
- "communicate with its Python execution server. Either "
- "no networking is installed on this computer or another "
- "process (another IDLE?) is using the port. Run IDLE with the -n "
- "command line switch to start without a subprocess and refer to "
- "Help/IDLE Help 'Running without a subprocess' for further "
- "details.",
+ "IDLE can't bind to a TCP/IP port, which is necessary to "
+ "communicate with its Python execution server. This might be "
+ "because no networking is installed on this computer. "
+ "Run IDLE with the -n command line switch to start without a "
+ "subprocess and refer to Help/IDLE Help 'Running without a "
+ "subprocess' for further details.",
master=self.tkconsole.text)
def display_no_subprocess_error(self):
@@ -1270,7 +1283,7 @@ def main():
global flist, root, use_subprocess
use_subprocess = True
- enable_shell = False
+ enable_shell = True
enable_edit = False
debug = False
cmd = None
@@ -1295,6 +1308,7 @@ def main():
enable_shell = True
if o == '-e':
enable_edit = True
+ enable_shell = False
if o == '-h':
sys.stdout.write(usage_msg)
sys.exit()
@@ -1345,7 +1359,6 @@ def main():
edit_start = idleConf.GetOption('main', 'General',
'editor-on-startup', type='bool')
enable_edit = enable_edit or edit_start
- enable_shell = enable_shell or not edit_start
# start editor and/or shell windows:
root = Tk(className="Idle")
fixwordbreaks(root)
diff -up Python-2.4.3/Lib/idlelib/rpc.py.idle-ports Python-2.4.3/Lib/idlelib/rpc.py
--- Python-2.4.3/Lib/idlelib/rpc.py.idle-ports 2004-02-12 12:35:32.000000000 -0500
+++ Python-2.4.3/Lib/idlelib/rpc.py 2010-09-08 16:22:36.000000000 -0400
@@ -515,8 +515,6 @@ class RPCClient(SocketIO):
def __init__(self, address, family=socket.AF_INET, type=socket.SOCK_STREAM):
self.listening_sock = socket.socket(family, type)
- self.listening_sock.setsockopt(socket.SOL_SOCKET,
- socket.SO_REUSEADDR, 1)
self.listening_sock.bind(address)
self.listening_sock.listen(1)