node module (begin code exploration from here!)

class pyrlang.node.Node(node_name: str, cookie: str, engine: pyrlang.async_support.base_engine.BaseEngine)

Bases: pyrlang.bases.BaseNode

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.

Example:

  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@127.0.0.1", "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.

Parameters:
  • ref (term.reference.Reference) -- Reference which you received when setting up a monitor.
  • origin_pid (Pid) -- The process who was monitoring the target previously
  • target (Pid or Atom) -- Name or pid of a monitor target process, possibly it does not exist
Raises:

ProcessNotFound -- if target does not exist

destroy()

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

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?

handle_one_inbox_message(m: tuple)

Handler is called whenever a message arrives to the mailbox.

inbox_ = None

Message queue based on gevent.Queue. It is periodically checked in the _run method and the receive handler is called.

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

Parameters:
  • pid1 (term.pid.Pid) -- First pid
  • pid2 (term.pid.Pid) -- Second pid
  • local_only -- If set to True, linking to remote pids will send LINK message over distribution protocol
monitor_process(origin_pid: term.pid.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.

Parameters:
  • ref (None or term.reference.Reference) -- If not None, will be reused, else a new random ref will be generated.
  • origin_pid (term.pid.Pid) -- The (possibly remote) process who will be monitoring the target from now and wants to know when we exit.
  • target (term.pid.Pid or term.atom.Atom) -- Name or pid of a monitor target process.
Return type:

term.reference.Reference

Raises:

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

node_db = <pyrlang.bases.NodeDB object>
on_exit_process(exiting_pid, reason)
pid_counter_ = None

An internal counter used to generate unique process ids

register_name(proc, name) → None

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

Parameters:
  • proc (Process) -- The process to register
  • name (Atom) -- The name to register with
register_new_process(proc=None) → term.pid.Pid

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

Parameters:proc (Process or None) -- A new process which needs a pid, or None if you only need a fake pid
Returns:A new pid (does not modify the process in place, so please store the pid!)
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.

Parameters:
  • sender (term.pid.Pid or None) -- Message sender
  • receiver (term.pid.Pid 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.

Delivers exit message due to a linked process dead to a local or remote process.

signal_wake_up(pid)

Process informs Node that it now has a signal in its signals queue. Try and process it when possible.

Mutually unlink two processes.

Parameters:
  • pid1 (term.pid.Pid) -- First pid
  • pid2 (term.pid.Pid) -- Second pid
  • local_only -- If set to True, linking to remote pids will send UNLINK message over distribution protocol
where_is(ident)

Look up a registered name or pid.

Parameters:ident (term.atom.Atom or term.pid.Pid) -- an Atom or a Pid to convert to a Pid
Return type:term.pid.Pid
where_is_process(ident)

Look up a registered name or pid.

Return type:pyrlang.process.Process or None
exception pyrlang.node.NodeException(msg, *args, **kwargs)

Bases: Exception

exception pyrlang.node.ProcessNotFoundError(msg, *args, **kwargs)

Bases: pyrlang.node.NodeException