@@ -163,6 +163,17 @@ def check_and_update():
163163 timer .start ()
164164
165165
166+ def get_available_port (start_port = 8001 , end_port = 8010 ):
167+ import socket
168+ for port in range (start_port , end_port ):
169+ try :
170+ with socket .socket (socket .AF_INET , socket .SOCK_STREAM ) as s :
171+ s .bind (("localhost" , port ))
172+ return port
173+ except OSError :
174+ continue
175+ return 8001
176+
166177def main ():
167178 parser = ArgumentParser (description = "Run the pipeline" )
168179 parser .add_argument ("pipeline" , metavar = "PIPELINE" , type = str ,
@@ -189,9 +200,9 @@ def main():
189200 "(default: localhost)" ,
190201 metavar = "HOST" , type = str , default = "localhost" )
191202 parser .add_argument ("--port" , dest = "port_number" ,
192- help = "the port number for the web interface "
193- "(default: 8001) " ,
194- metavar = "PORT" , type = int , default = 8001 )
203+ help = "the port number for the web interface. "
204+ "Defaults to 8001. Will attempt to get the next available port if 8001 is in use. " ,
205+ metavar = "PORT" , type = int , default = get_available_port () )
195206 parser .add_argument ("--http-username" , dest = "http_username" ,
196207 help = "username for the web interface (default: admin)" ,
197208 metavar = "USERNAME" , type = str
0 commit comments