(times=20)
Ensure that JupyterHub is up and running

    Loops given number of times, waiting a second each.
Ensure that JupyterHub is up and running
Ensure that JupyterHub is up and running
def ensure_jupyterhub_running(times=20):
    """
    Ensure that JupyterHub is up and running

    Loops given number of times, waiting a second each.
    """

    for i in range(times):
        try:
            logger.info(f"Waiting for JupyterHub to come up ({i + 1}/{times} tries)")
            # Because we don't care at this level that SSL is valid, we can suppress
            # InsecureRequestWarning for this request.
            with warnings.catch_warnings():
                warnings.filterwarnings("ignore", category=InsecureRequestWarning)
                requests.get("http://127.0.0.1", verify=False)
            return
        except requests.HTTPError as h:
            if h.response.status_code in [404, 502, 503]:
                # May be transient
                time.sleep(1)
                continue
            # Everything else should immediately abort
            raise
        except requests.ConnectionError:
            # Hub isn't up yet, sleep & loop
            time.sleep(1)
            continue
        except Exception:
            # Everything else should immediately abort
            raise

    raise Exception(f"Installation failed: JupyterHub did not start in {times}s")
def ensure_jupyterhub_running ( times = 20 ) : for i in range ( times ) : try : logger . info ( f"Waiting for JupyterHub to come up ({i + 1}/{times} tries)" ) # Because we don't care at this level that SSL is valid, we can suppress # InsecureRequestWarning for this request. with warnings . catch_warnings ( ) : warnings . filterwarnings ( "ignore" , category = InsecureRequestWarning ) requests . get ( "http://127.0.0.1" , verify = False ) return except requests . HTTPError as h : if h . response . status_code in [ 404 , 502 , 503 ] : # May be transient time . sleep ( 1 ) continue # Everything else should immediately abort raise except requests . ConnectionError : # Hub isn't up yet, sleep & loop time . sleep ( 1 ) continue except Exception : # Everything else should immediately abort raise raise Exception ( f"Installation failed: JupyterHub did not start in {times}s" )