INNER CODE UNIT · Python

jarvis_api

thevickypedia/Jarvis · jarvis/api/server.py:13

def jarvis_api() -> None:
    """Initiates the fast API in a dedicated process using uvicorn server.

    See Also:
        - Checks if the port is being used. If so, makes a ``GET`` request to the endpoint.
        - Attempts to kill the process listening to the port, if the endpoint doesn't respond.
    """
    multiprocessing_logger(filename=APIConfig().DEFAULT_LOG_FILENAME)
    # noinspection HttpUrlsUsage
    url = f"http://{models.env.offline_host}:{models.env.offline_port}"

    if port_handler.is_port_in_use(port=models.env.offline_port):
        logger.info("%d is currently in use.", models.env.offline_port)

        try:
            res = requests.get(url=url, timeout=1)
            if res.ok:
                logger.info("'%s' is accessible.", url)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…