pyrlang.process¶
Python processes with a pid, an inbox, links and monitors.
- class pyrlang.process.BacklogOwner(*args, **kwargs)¶
Bases:
ProtocolA connection that counts the messages it delivered into inboxes and that no process has taken out yet (its receive backlog, for flow control).
- backlog_add(nbytes)¶
A message of
nbyteswent into an inbox.
- backlog_release(nbytes)¶
A message of
nbyteswas taken out of an inbox.
- pyrlang.process.delivering(owner, nbytes=0)¶
Make messages put into inboxes from now on count towards the backlog of
owner(None: towards no connection).
- class pyrlang.process.Process(passive=False)¶
Bases:
objectImplements 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 it and handle incoming messages in
handle_one_inbox_message(self, msg).Note
Only a
Processcan 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.- node_db = <pyrlang.node_db.NodeDB object>¶
- passive_: bool¶
Having
passive=Truewill only wake up thisProcesswhen a message arrives, to handle it, otherwise it will not get any CPU time for any empty polling loops. Havingpassive=Falsewill runprocess_loop()polling inbox.
- inbox_: Queue[Any]¶
Message queue. Messages are detected by the
_runloop and handled one by one inhandle_one_inbox_message(). Messages from another node that wait here hold back reading from that node’s connection once there are too many (seeNode).
- inbox_rejects_: Queue[Any]¶
Used for selective receives. Stores messages which did not match while the rest of the inbox is scanned.
- pid_¶
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 fromself.inbox_.
- async receive(match=None, timeout=None, timeout_callback=None)¶
The next message that matches, as Erlang’s selective
receive; messages that do not match stay in the inbox.- Parameters:
- Raises:
pyrlang.errors.ProcessTimeoutError – on a timeout without a callback
- Returns:
what the handler of the matching pattern returns
- Return type:
- async handle_signals()¶
Called from Node if the Node knows that there’s a signal waiting to be handled.
- handle_inbox()¶
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.
- handle_message_from(sender, msg)¶
Override this instead of
handle_one_inbox_messageto also learn who sent the message: the sender’s pid, or None if it is not known (a sender that gave none; a remote sender when the message came as SEND, which carries no sender). Called forpassiveprocesses only; a process with an inbox gets messages without their senders.
- deliver_message(msg, sender=None)¶
Places message into the inbox, or delivers it immediately to a handler (if process is
passive).
- alias()¶
Create a process alias (EEP 53): a reference that can be used as a destination of
Node.sendhere and of!on Erlang nodes, untilunalias()is called or the process exits. Useful as the reply address of a request: late replies to a removed alias are dropped instead of piling up in the inbox.
- unalias(alias)¶
Deactivate an alias of this process.
- Returns:
True if it was an active alias of this process
- Return type:
- links()¶
The processes this one is linked to (active links only).
- monitors()¶
The monitors this process holds: reference -> monitored pid, as Erlang’s
process_info(P, monitors).
- monitored_by()¶
The monitors on this process: reference -> monitoring pid, as Erlang’s
process_info(P, monitored_by).
- links_to_node(node_name)¶
Pids on
node_namethis process has link information about, active or being unlinked.
- monitors_to_node(node_name)¶
The monitors this process holds on processes of
node_name.
- forget_monitors_from_node(node_name)¶
The connection to
node_nameis gone: the monitors its processes held on this one end without a message, as in OTP.
- remove_link(pid)¶
Unlinks pid from this process at once, without the unlink protocol. Please use Node method
unlink()for proper unlinking.
- link_sent(pid)¶
This process links to
pid: the link becomes active and an outstanding unlink is forgotten.- Returns:
True if a LINK signal has to be sent (the link was not active)
- Return type:
- link_received(pid)¶
A LINK signal from
pid: creates an active link, unless there is link information already (an unacknowledged unlink stays so).
- unlink_sent(pid, unlink_id)¶
This process unlinks
pid: the link becomes inactive until the other side acknowledgesunlink_id.- Returns:
True if an UNLINK_ID signal has to be sent (the link was active)
- Return type:
- unlink_received(pid)¶
An UNLINK_ID signal from
pid: an active link is removed; with an unlink of our own outstanding nothing changes.
- unlink_acked(pid, unlink_id)¶
An UNLINK_ID_ACK signal from
pid: ends our unlink if it is the one withunlink_id.
- link_broken(pid)¶
An exit signal due to the link with
pid(it exited, or the connection to its node was lost): the link information is removed.- Returns:
True if the link was active, so the signal has to be acted on
- Return type:
- 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()¶
The node this process belongs to.
- add_monitor(pid, ref)¶
Helper function. To monitor a process please use Node’s
monitor_process().
- add_monitored_by(pid, ref)¶
Helper function. To monitor a process please use Node’s
monitor_process().
- monitor_fired(ref)¶
The monitor
refthis process holds fired: it ends here.- Returns:
True if it was active, so the ‘DOWN’ message is delivered
- Return type:
- remove_monitor(pid, ref)¶
Helper function. To demonitor a process please use Node’s
demonitor_process().
- remove_monitored_by(pid, ref)¶
Helper function. To demonitor a process please use Node’s
demonitor_process().