process module

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

Bases: term.bases.BaseProcess

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).

engine_ = None

Pluggable async event engine. Use this to get access to async tasks, sleeps and socket services.

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: pyrlang.node.Node

handle_inbox()

Do not override handle_inbox, instead go for handle_one_inbox_message

handle_one_inbox_message(msg)

Override this method to handle new incoming messages.

handle_signals()

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

inbox_ = None

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

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

Convenience field to see the Node (from Node.all_nodes[name]).

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.

process_loop() → bool

Polls inbox in an endless loop. Returns True to continue running. Return False to stop.

Note

This will not be executed if the process was constructed with passive=True (the default).

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().