@@ -65,8 +65,10 @@ def find_free_port():
65
65
s .bind (('' , 0 )) # find an available port
66
66
return s .getsockname ()[1 ]
67
67
68
-
69
- __HTTP_PORT = find_free_port ()
68
+ if "VPYTHON_HTTP_PORT" in os .environ :
69
+ __HTTP_PORT = int (os .environ ["VPYTHON_HTTP_PORT" ])
70
+ else :
71
+ __HTTP_PORT = find_free_port ()
70
72
__SOCKET_PORT = find_free_port ()
71
73
72
74
try :
@@ -259,19 +261,24 @@ def onClose(self, wasClean, code, reason):
259
261
260
262
261
263
try :
264
+ no_launch = os .environ .get ("VPYTHON_NO_LAUNCH_BROWSER" , False )
265
+ if no_launch == "0" :
266
+ no_launch = False
262
267
if platform .python_implementation () == 'PyPy' :
263
268
server_address = ('' , 0 ) # let HTTPServer choose a free port
264
269
__server = HTTPServer (server_address , serveHTTP )
265
270
port = __server .server_port # get the chosen port
266
271
# Change the global variable to store the actual port used
267
272
__HTTP_PORT = port
268
- _webbrowser .open ('http://localhost:{}' .format (port )
273
+ if not no_launch :
274
+ _webbrowser .open ('http://localhost:{}' .format (port )
269
275
) # or webbrowser.open_new_tab()
270
276
else :
271
277
__server = HTTPServer (('' , __HTTP_PORT ), serveHTTP )
272
278
# or webbrowser.open_new_tab()
273
- if _browsertype == 'default' : # uses default browser
274
- _webbrowser .open ('http://localhost:{}' .format (__HTTP_PORT ))
279
+ if not no_launch :
280
+ if _browsertype == 'default' : # uses default browser
281
+ _webbrowser .open ('http://localhost:{}' .format (__HTTP_PORT ))
275
282
276
283
except :
277
284
pass
0 commit comments