process module

class pyrlang.process.Process(passive: bool = False)

Bases: object

Implements Erlang process semantic and lifetime. Registers itself in the process registry, can receive and send messages. To optionally register self with a name, call node.register_name(self, term.Atom('fgsfds'))

Subclass the Process to run your logic in its _loop() -> bool function or to handle incoming messages via handle_one_inbox_message(self, msg).

Note

Only a Process can serve as a target for sending messages, for linking and monitoring. You do not need to create a Process for simple one-way interactions with remote Erlang nodes.

Links pid to this process. Please use Node method link() for proper linking.

add_monitor(pid: term.pid.Pid, ref: term.reference.Reference)

Helper function. To monitor a process please use Node's monitor_process().

add_monitored_by(pid: term.pid.Pid, ref: term.reference.Reference)

Helper function. To monitor a process please use Node's monitor_process().

deliver_message(msg)

Places message into the inbox, or delivers it immediately to a handler (if process is passive).

exit(reason=None)

Marks the object as exiting with the reason, informs links and monitors and unregisters the object from the node process dictionary.

get_node()

Finds current node from global nodes dict by self.node_name_. A convenient way to access the node which holds the current process. :rtype: pyrlang2.node.Node

handle_inbox() → int

Do not override handle_inbox, instead go for handle_one_inbox_message :returns: How many messages have been handled

handle_one_inbox_message(msg)

Override this method to handle new incoming messages.

async handle_signals()

Called from Node if the Node knows that there's a signal waiting to be handled.

inbox_ = None

Message queue. Messages are detected by the _run loop and handled one by one in handle_one_inbox_message().

node_db = <pyrlang.node_db.NodeDB object>
node_name_ = None

Convenience field to see the Node

passive_ = None

Having passive=True will only wake up this Process when a message arrives, to handle it, otherwise it will not get any CPU time for any empty polling loops. Having passive=False will run process_loop`() polling inbox.

pid_ = None

Process identifier for this object. Remember that when creating a process, it registers itself in the node, and this creates a reference. References prevent an object from being garbage collected. To destroy a process, get rid of this extra reference by calling exit() and telling it the cause of its death.

async process_loop()

Polls inbox in an endless loop. .. note:

This will not be executed if the process was constructed with
``passive=True`` (the default). Passive processes should read
their inbox directly from ``self.inbox_``.
async receive(match=None, timeout=None, timeout_callback=None)

Unlinks pid from this process. Please use Node method unlink() for proper unlinking.

remove_monitor(pid: term.pid.Pid, ref: term.reference.Reference)

Helper function. To demonitor a process please use Node's demonitor_process().

remove_monitored_by(pid: term.pid.Pid, ref: term.reference.Reference)

Helper function. To demonitor a process please use Node's demonitor_process().