Exemple #1
0
def perform_notebook_request(notebook_path: str, command_name: str, data: Dict[str, Any]) -> None:
    J_LOGGER.debug("Performing notebook request... ")

    notebook_server = get_server_for_notebook(notebook_path)
    if notebook_server is None:
        J_LOGGER.warning("==> Unable to process request")
        J_LOGGER.warning("==> {}", _REGISTERED_SERVERS)
        return

    request(notebook_server, command_name, data=data)
Exemple #2
0
def request_notebook_command(json_request: GenericJsonRequest):
    try:
        request(
            EXECUTE_HOST_URL,
            perform_notebook_request.__name__,
            command_name=_map_json_request_to_function_name(json_request),
            notebook_path=json_request.file_name,
            data=attr.asdict(json_request),
        )
    except ConnectionError as e:
        J_LOGGER.warning(f"Unable to connect to server. Perhaps notebook is not running? {e}")
    except ReceivedNon2xxResponseError as e:
        J_LOGGER.warning(f"Unable to process request. Perhaps something else is running on this port? {e}")
def perform_notebook_request(notebook_path: str, command_name: str,
                             data: Dict[str, Any]) -> Optional[Dict]:
    J_LOGGER.debug("Performing notebook request... ")

    try:
        notebook_server = get_server_for_notebook(notebook_path)
    except UnableToFindNotebookException:
        J_LOGGER.warning(
            f"Unabled to find {notebook_path} in {_REGISTERED_SERVERS}")
        return {"success": False, "notebook_path": notebook_path}

    request(notebook_server, command_name, data=data)

    return None
Exemple #4
0
def get_server_for_notebook(notebook_path: str) -> Optional[str]:
    # Normalize to notebook path
    notebook_path = notebook_path.replace(".synced.py", ".synced.ipynb")

    J_LOGGER.debug("Finding server for notebook_path, script_path: {}", notebook_path)

    potential_notebooks: List[str] = []
    for registered_name in _REGISTERED_SERVERS:
        if registered_name in notebook_path:
            potential_notebooks.append(registered_name)

    if len(potential_notebooks) > 1:
        J_LOGGER.warning("Found more than one notebook {}, {}", notebook_path, potential_notebooks)
        return None
    elif len(potential_notebooks) == 1:
        notebook_port = _REGISTERED_SERVERS[potential_notebooks[0]]

        J_LOGGER.debug("Found server at port {}", notebook_port)
        return f"http://localhost:{notebook_port}"
    else:
        J_LOGGER.warning("Could not find server for notebook_path: {}", notebook_path)
        return None
Exemple #5
0
 def _recv(msg):
     print(msg)
     J_LOGGER.warning(msg)