# `Pyro5.server` — Server (daemon) logic

Server related classes (Daemon etc)

class Pyro5.server.Daemon(host=None, port=0, unixsocket=None, nathost=None, natport=None, interface=<class 'Pyro5.server.DaemonObject'>, connected_socket=None)

  Pyro daemon. Contains server side logic and dispatches incoming remote method calls to the appropriate objects.

  annotations()

    Override to return a dict with custom user annotations to be sent with each response message.

  clientDisconnect(conn)

    Override this to handle a client disconnect. Conn is the SocketConnection object that was disconnected.

  close()

    Close down the server and release resources

  combine(daemon)

    Combines the event loop of the other daemon in the current daemon’s loop. You can then simply run the current daemon’s requestLoop to serve both daemons. This works fine on the multiplex server type, but doesn’t work with the threaded server type.

  events(eventsockets)

    for use in an external event loop: handle any requests that are pending for this daemon

  handleRequest(conn)

    Handle incoming Pyro request. Catches any exception that may occur and wraps it in a reply to the calling side, as to not make this server side loop terminate due to exceptions caused by remote invocations.

  housekeeping()

    Override this to add custom periodic housekeeping (cleanup) logic. This will be called every few seconds by the running daemon’s request loop.

  locationStr

    The location (str of the form `host:portnumber`) on which the Daemon is listening

  proxyFor(objectOrId, nat=True)

    Get a fully initialized Pyro Proxy for the given object (or object id) for this daemon. If nat is False, the configured NAT address (if any) is ignored. The object or id must be registered in this daemon, or you’ll get an exception. (you can’t get a proxy for an unknown object)

  register(obj_or_class, objectId=None, force=False, weak=False)

    Register a Pyro object under the given id. Note that this object is now only known inside this daemon, it is not automatically available in a name server. This method returns a URI for the registered object. Pyro checks if an object is already registered, unless you set force=True. You can register a class or an object (instance) directly. For a class, Pyro will create instances of it to handle the remote calls according to the instance_mode (set via @expose on the class). The default there is one object per session (=proxy connection). If you register an object directly, Pyro will use that single object for all remote calls. With weak=True, only weak reference to the object will be stored, and the object will get unregistered from the daemon automatically when garbage-collected.

  requestLoop(loopCondition=<function Daemon.<lambda>>) → None

    Goes in a loop to service incoming requests, until someone breaks this or calls shutdown from another thread.

  resetMetadataCache(objectOrId, nat=True)

    Reset cache of metadata when a Daemon has available methods/attributes dynamically updated. Clients will have to get a new proxy to see changes

  property selector

    the multiplexing selector used, if using the multiplex server type

  static serveSimple(objects, host=None, port=0, daemon=None, ns=True, verbose=True) → None

    Backwards compatibility method to fire up a daemon and start serving requests. New code should just use the global `serve` function instead.

  shutdown()

    Cleanly terminate a daemon that is running in the requestloop.

  property sock

    the server socket used by the daemon

  property sockets

    list of all sockets used by the daemon (server socket and all active client sockets)

  unregister(objectOrId)

    Remove a class or object from the known objects inside this daemon. You can unregister the class/object directly, or with its id.

  uriFor(objectOrId, nat=True)

    Get a URI for the given object (or object id) from this daemon. Only a daemon can hand out proper uris because the access location is contained in them. Note that unregistered objects cannot be given an uri, but unregistered object names can (it’s just a string we’re creating in that case). If nat is set to False, the configured NAT address (if any) is ignored and it will return an URI for the internal address.

  validateHandshake(conn, data)

    Override this to create a connection validator for new client connections. It should return a response data object normally if the connection is okay, or should raise an exception if the connection should be denied.

class Pyro5.server.DaemonObject(daemon)

  The part of the daemon that is exposed as a Pyro object.

  get_metadata(objectId)

    Get metadata for the given object (exposed methods, oneways, attributes).

  info()

    return some descriptive information about the daemon

  ping()

    a simple do-nothing method for testing purposes

  registered()

    returns a list of all object names registered in this daemon

Pyro5.server.behavior(instance_mode: str = 'session', instance_creator: Optional[Callable] = None) → Callable

  Decorator to specify the server behavior of your Pyro class.

Pyro5.server.callback(method: Callable) → Callable

  decorator to mark a method to be a ‘callback’. This will make Pyro raise any errors also on the callback side, and not only on the side that does the callback call.

Pyro5.server.expose(method_or_class: _T) → _T

  Decorator to mark a method or class to be exposed for remote calls. You can apply it to a method or a class as a whole. If you need to change the default instance mode or instance creator, also use a @behavior decorator.

Pyro5.server.oneway(method: Callable) → Callable

  decorator to mark a method to be oneway (client won’t wait for a response)

Pyro5.server.serve(objects: Dict[Any, str], host: Optional[Union[str, IPv4Address, IPv6Address]] = None, port: int = 0, daemon: Optional[Daemon] = None, use_ns: bool = True, verbose: bool = True) → None

  Basic method to fire up a daemon (or supply one yourself). objects is a dict containing objects to register as keys, and their names (or None) as values. If ns is true they will be registered in the naming server as well, otherwise they just stay local. If you need to publish on a unix domain socket, or require finer control of the daemon’s behavior, you can’t use this shortcut method. Create a Daemon yourself and use its appropriate methods. See the documentation on ‘publishing objects’ (in chapter: Servers) for more details.