def serve_webapp(webapp, port=None, host=None):
 server = None
 if (port is not None):
  server = httpserver.serve(webapp, host=host, port=port, start_loop=False)
 else:
  random.seed()
  for i in range(0, 9):
   try:
    port = str(random.randint(8000, 10000))
    server = httpserver.serve(webapp, host=host, port=port, start_loop=False)
    break
   except socket.error as e:
    if (e[0] == 98):
     continue
    raise
  else:
   raise Exception(('Unable to open a port between %s and %s to start Galaxy server' % (8000, 1000)))
 t = threading.Thread(target=server.serve_forever)
 t.start()
 return (server, port)

def serve_webapp ( webapp , port = None , host = None ) : server = None if ( port is not None ) : server = httpserver . serve ( webapp , host = host , port = port , start_loop = False ) else : random . seed ( ) for i in range ( 0 , 9 ) : try : port = str ( random . randint ( 8000 , 10000 ) ) server = httpserver . serve ( webapp , host = host , port = port , start_loop = False ) break except socket . error as e : if ( e [ 0 ] == 98 ) : continue raise else : raise Exception ( ( 'Unable to open a port between %s and %s to start Galaxy server' % ( 8000 , 1000 ) ) ) t = threading . Thread ( target = server . serve_forever ) t . start ( ) return ( server , port )
serve the webapp on a recommend port or a free one .