def wait_for_port_to_be_open(port_number): """Wait until the port is open. Args: port_number: int. The port number to wait. """ waited_seconds = 0 while (not common.is_port_open(port_number) and waited_seconds < MAX_WAIT_TIME_FOR_PORT_TO_OPEN_SECS): time.sleep(1) waited_seconds += 1 if (waited_seconds == MAX_WAIT_TIME_FOR_PORT_TO_OPEN_SECS and not common.is_port_open(port_number)): python_utils.PRINT('Failed to start server on port %s, exiting ...' % port_number) sys.exit(1)
def is_oppia_server_already_running(): """Check if the ports are taken by any other processes. If any one of them is taken, it may indicate there is already one Oppia instance running. Returns: bool. Whether there is a running Oppia instance. """ for port in [OPPIA_SERVER_PORT, GOOGLE_APP_ENGINE_PORT]: if common.is_port_open(port): python_utils.PRINT( 'There is already a server running on localhost:%s.' 'Please terminate it before running the end-to-end tests.' 'Exiting.' % port) return True return False