@@ -65,8 +65,10 @@ def find_free_port():
6565 s .bind (('' , 0 )) # find an available port
6666 return s .getsockname ()[1 ]
6767
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 ()
7072__SOCKET_PORT = find_free_port ()
7173
7274try :
@@ -259,19 +261,24 @@ def onClose(self, wasClean, code, reason):
259261
260262
261263try :
264+ no_launch = os .environ .get ("VPYTHON_NO_LAUNCH_BROWSER" , False )
265+ if no_launch == "0" :
266+ no_launch = False
262267 if platform .python_implementation () == 'PyPy' :
263268 server_address = ('' , 0 ) # let HTTPServer choose a free port
264269 __server = HTTPServer (server_address , serveHTTP )
265270 port = __server .server_port # get the chosen port
266271 # Change the global variable to store the actual port used
267272 __HTTP_PORT = port
268- _webbrowser .open ('http://localhost:{}' .format (port )
273+ if not no_launch :
274+ _webbrowser .open ('http://localhost:{}' .format (port )
269275 ) # or webbrowser.open_new_tab()
270276 else :
271277 __server = HTTPServer (('' , __HTTP_PORT ), serveHTTP )
272278 # 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 ))
275282
276283except :
277284 pass
0 commit comments