def get_context(pid_file, daemon=False):
    """Get context of running notebook.

    A context file is created when notebook starts.

    :param daemon: Are we trying to fetch the context inside the daemon. Otherwise do the death check.

    :return: dict or None if the process is dead/not launcherd
    """
    port_file = get_context_file_name(pid_file)

    if not os.path.exists(port_file):
        return None

    with open(port_file, "rt") as f:
        json_data = f.read()
        try:
            data = json.loads(json_data)
        except ValueError as e:

            logger.error("Damaged context json data %s", json_data)
            return None

        if not daemon:
            pid = data.get("pid")
            if pid and not check_pid(int(pid)):
                # The Notebook daemon has exited uncleanly, as the PID does not point to any valid process
                return None

        return data
def get_context ( pid_file , daemon = False ) : port_file = get_context_file_name ( pid_file ) if not os . path . exists ( port_file ) : return None with open ( port_file , "rt" ) as f : json_data = f . read ( ) try : data = json . loads ( json_data ) except ValueError as e : logger . error ( "Damaged context json data %s" , json_data ) return None if not daemon : pid = data . get ( "pid" ) if pid and not check_pid ( int ( pid ) ) : return None return data
Get context of running notebook.

    A context file is created when notebook starts.

    :param daemon: Are we trying to fetch the context inside the daemon. Otherwise do the death check.

    :return: dict or None if the process is dead/not launcherd