def running_server()

in l10n_CM/run_l10n.py [0:0]


def running_server(live_site, test_region):
    """Context manager to run a server and clean it up automatically."""
    html_path = os.path.join(current_dir, "sites", live_site, test_region)
    if not os.path.exists(html_path):
        raise FileNotFoundError(
            f"Expected HTML directory not found at path: {html_path}"
        )

    httpd, server_thread = start_server(live_site, test_region)
    try:
        yield  # control goes to the caller, server runs in the background
    finally:
        try:
            # Send a dummy request to unblock the server if necessary
            requests.get(f"http://{LOCALHOST}:{PORT}")
        except Exception:
            pass
        httpd.shutdown()
        server_thread.join()
        logging.info(f"{live_site} server shutdown.")