pyrlang.gen.gen_server

Example of how to inherit from GenServer:

class MyProcess(GenServer):
    def __init__(self, node) -> None:
        GenServer.__init__(self, node, accepted_calls=['hello'])

    def hello(self):
        return self.pid_
class pyrlang.gen.gen_server.GenServerMeta(name, bases, nmspc)

Bases: type

Meta class for GenServer

Looks for functions that have been decorated and adds them to match functions

class pyrlang.gen.gen_server.GenServer

Bases: Process

A process that answers gen_server:call and gen_server:cast from Erlang and from Python.

Subclass it and mark handler methods with the decorators of pyrlang.gen.decorators: @call(order, pattern), @cast(order, pattern) and @info(order, pattern). A request goes to the handler with the lowest order whose pattern (a function of the request) is true. What a call handler returns is the reply.

timeout(seconds=None)

set the gen_server timeout, will generate inbox Atom(‘timeout’) :param seconds: :return:

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_``.
class pyrlang.gen.gen_server.GenServerInterface(calling_process, destination_pid)

Bases: object

Class that implements an interface for gen_servers

This class is intended to be used in Process instances where gen_server behaviour interaction is necessary.

in a raw form this class is initiated with the calling process instance and the pid of the destination process, then you can make calls and cast:

gsi = GenServerInterface(some_process, remote_pid) await gsi.call(call_request) await gsi.cast(cast_request) gsi.cast_nowait(other_cast_request)

If you want to create an interface you override this class and implement the functions, hiding the gen_server methods, just like in erlang

async call(request, timeout=5)

gen_server:call: send request and wait for the reply.

Parameters:

timeout (float | None) – seconds; None waits for ever

Raises:

pyrlang.errors.ProcessTimeoutError – no reply in time

async cast(request)

gen_server:cast: send request; there is no reply.

cast_nowait(request)

As cast(), from code that is not a coroutine.