nxt.session module

class Session[source]

Bases: object

Nxt Session, manages loading, saving, and execution of graphs.

property loaded_files
new_file()[source]

Create a new (empty) graph.

Returns

New graph object.

get_unused_graph_name(name)[source]

Used by new_file() to make sure that any new graph created won’t conflict with the names of currently open graphs.

Parameters

name (str) – Name preference, adjusted to remove conflicts if needed.

Returns

Resulting name, may not match input name preference.

load_file(filepath)[source]

Create a new graph from given filepath.

Parameters

filepath (str) – Path to .json file to load.

Returns

New graph object, if load succeeded. Otherwise None.

Return type

Graph

unload_file(uid)[source]
save_file(graph_file_path, new_path=None)[source]

The file to save is specified via graph_file_path. If new_path is specified, it will change the path used to identify the graph in the future.

Parameters
  • graph_file_path (str) – path used to locate file to save in currently loaded files.

  • new_path (str) – If specified, saves the specified file to a new path.

Returns

True/False if successful

save_layer(layer, filepath=None, as_copy=False)[source]
get_stage(path)[source]

Get the graph object for a specified file path. If the file is not already loaded, it will be.

Parameters

path (str) – Path to file the graph is loaded from.

Returns

Graph object, if found, otherwise None.

execute_graph(filepath, start=None, parameters=None, context=None)[source]

Execute the graph at the given file path. Optionally at given start. You may provided parameters to the parameter arg. The data should be formatted as follows:

{
    '/node.attr': 'New value!',
    '/another.count: 5
}

If the node does not exist an error will be logged but the execution will continue. If the attr does not exist (but the node does) it will be created.

Parameters
  • filepath (str) – Path to the graph file.

  • start (str or int) – Path to the node to begin execution from OR int of start node index

  • parameters (dict) – Dict where key is attr path and value is new attr value.

  • context (str) – Optional name of remote context to execute graph in, if none is passed the graph is executed in this interpreter.

Returns

a runtime CompLayer.

execute_nodes(filepath, node_paths, parameters=None)[source]
start_rpc_if_needed(stage)[source]

Given a stage this method parses for the remote context node, if it is found in the stage’s sub_layers an rpc is started. (if one is already run a new on will NOT be started)

Parameters

stage – stage.Stage instance

Returns

None

shutdown_rpc_server()[source]

Attempts to close THIS session’s rpc server, if this session doesn’t own the server it will not shut it down. :return: None

class RPCServerProcess(use_custom_stdout=False, stdout_filepath=None, socket_log=False, stream_handler=None)[source]

Bases: object

STARTUP_TIMEOUT = 5
classmethod start(use_custom_stdout=False, stdout_filepath=None, socket_log=False, stream_handler=None)[source]

Quick start method for starting and returning a server if needed

Parameters
  • use_custom_stdout – see __init__

  • stdout_filepath – see __init__

  • socket_log – see __init__

Returns

None or RPCServerProcess instance

run()[source]

Method for starting rpc server sub-process

Raises

OSError

Returns

True if server was started, else False.

is_running()[source]

Attempts to connect to the rpc server as a client, if that fails because the connection is refused the subprocess is polled. If this instance doesn’t own the subprocess and it fails to connect as a client False is returned.

Returns

bool of server running state

terminate()[source]

Attempts to kill the rpc server. Note: The server is killed even if it isn’t owned by this class!

Returns

None

static is_port_available()[source]

Checks if the rpc port is occupied. :return: bool