node module (begin code exploration from here!)

class pyrlang.node.Node(node_name: str, cookie: str, hidden: bool = False)

Bases: object

Implements an Erlang node which has a network name, a dictionary of processes and registers itself via EPMD. Node handles the networking asynchronously.

This is the root object of an Erlang node, it must be created first and must outlive all other objects it manages, for them to be accessible over the network.


  1. Create an async engine adapter:

    e = GeventEngine() # located in import Pyrlang

  2. Create a node class with a name and a cookie

    node = Pyrlang.Node("py@", "COOKIE", engine=e)

  3. Start it via the engine adapter e.start(node)

  4. Now anything that you do (for example an infinite loop with

    e.sleep(1) in it, will give CPU time to the node.

demonitor_process(origin_pid, target, ref)

Locate the process target and remove the origin from its monitors_ collection. This does not trigger any notifications or signals to the origin.

  • ref (term.reference.Reference) -- Reference which you received when setting up a monitor.

  • origin_pid (Pid) -- The process who was monitoring the target before

  • target (Pid or Atom) -- Name or pid of a monitor target process, possibly it does not exist


ProcessNotFound -- if target does not exist


Closes incoming and outgoing connections and destroys the local node. This is Python, so some refs from running async handlers may remain.

async dist_command(receiver_node: str, message: tuple) → None

Locate the connection to the given node (a string). Place a tuple crafted by the caller into message box for Erlang dist_proto socket. It will pick up and handle the message whenever possible.

  • receiver_node -- Name of a remote node

  • message -- A crafted tuple with command name and some more values


NodeException -- if unable to find or connect to the node

exit_process(sender, receiver, reason)

Delivers exit message to a local or remote process.

Get string cookie value for this node. TODO: Cookie per connection?

async handle_signals()
inbox_ = None

Contains Pyrlang's own messages to the local node.

Check each of processes pid1 and pid2 if they are local, mutually link them. Assume remote process handles its own linking.

  • pid1 ( -- First pid

  • pid2 ( -- Second pid

  • local_only -- If set to True, linking to remote pids will send LINK message over dist_proto protocol

unsafe casting of link

you can't assume it has got effect when this function returns Convinience methot for being able to call it outside a async function

monitor_process(origin_pid:, target, ref=None)

Locate the process referenced by the target and place the origin pid into its monitors_ collection. When something happens to the target, a special message will be sent to the origin. Remote targets are supported.

  • ref (None or term.reference.Reference) -- If not None, will be reused, else a new random ref will be generated.

  • origin_pid ( -- The (possibly remote) process who will be monitoring the target from now and wants to know when we exit.

  • target ( or term.atom.Atom) -- Name or pid of a monitor target process.

Return type



pyrlang.node.ProcessNotFoundError -- if target does not exist.

node_db = <pyrlang.node_db.NodeDB object>

All existing local Node objects indexed by node_name: str

node_name_ = None

Node name as seen on the network. Use full node names here: name@hostname

node_opts_ = None

Distribution options object with feature support flags packed into an integer. The remote node will receive these flags to know what features we can support.

on_exit_process(exiting_pid, reason)
pid_counter_ = None

An internal counter used to generate unique process ids

processes_ = None

Process dictionary which stores all the existing Process objects adressable by a pid.


This creates a python reference to an object preventing its automatic garbage collection. In the end of its lifetime an object must be explicitly removed from this dictionary using Process.exit method on the process.

reg_names_ = None

Registered objects dictionary, which maps atoms to pids

register_dist_node(addr, proto)

add the protocol to dist nodes so that we can use it :param addr: :param proto: :return:

register_name(proc, name) → None

Add a name into registrations table (automatically removed when the referenced process is removed)

  • proc (Process) -- The process to register

  • name (Atom) -- The name to register with

register_new_process(proc=None) →

Generate a new pid and add the process to the process dictionary.


proc (Process or None) -- A new process which needs a pid, or None if you only need a fake pid


A new pid (does not modify the process in place, so please store the pid!)

async send(sender, receiver, message) → None

Deliver a message to a pid or to a registered name. The pid may be located on another Erlang node.

  • sender ( or None) -- Message sender

  • receiver ( or term.atom.Atom or Tuple[Atom, Pid or Atom]) -- Message receiver, a pid, or a name, or a tuple with node name and a receiver on the remote node.

  • message -- Any value which will be placed into the receiver inbox. Pyrlang processes use tuples but that is not enforced for your own processes.

send_nowait(sender, receiver, message) → None

Create task that sends the message


Mutually unlink two processes.

  • pid1 ( -- First pid

  • pid2 ( -- Second pid

  • local_only -- If set to True, linking to remote pids will send UNLINK message over dist_proto protocol


remove dist node (disconnected most likley) :param addr: :return:


Look up a registered name or pid.


ident (term.atom.Atom or -- an Atom or a Pid to convert to a Pid

Return type


Look up a registered name or pid.

Return type

pyrlang.process.Process or None