Example #1
0
 async def wait_port_async(port, timeout):
     start_time = time.time()
     started = is_port_in_use(port)
     while (time.time() - start_time) < timeout and started is False:
         await asyncio.sleep(1)
         started = is_port_in_use(port)
     return started
Example #2
0
                            args=(config_path, args.verbose))
            p.start()
            p_arr.append(p)
        except Exception as e:
            close_api_gracefully(p_arr)
            print(f'Failed to start {api_name} API with exception {e}')
            print(traceback.format_exc())
            raise

    atexit.register(close_api_gracefully, p_arr=p_arr)

    timeout = 15
    start_time = time.time()
    all_started = False
    while (time.time() - start_time) < timeout and all_started is False:
        all_started = True
        for i, api in enumerate(api_arr):
            try:
                in_use = api['started'] or is_port_in_use(api['port'])
            except Exception:
                # NOTE that hotfix for OSX: is_port_in_use will raise AccessDenied error if it runned not as sudo
                in_use = True
            if in_use and api['started'] != in_use:
                api['started'] = in_use
                print(f"{api['name']} API: started on {api['port']}")
            all_started = all_started and in_use
        time.sleep(0.5)

    for p in p_arr:
        p.join()