Blocking I/O with threads

This allows using a D-Bus connection from multiple threads. The router also launches a separate thread to receive incoming messages. See Connections and Routers for more about the two interfaces.

jeepney.io.threading.open_dbus_router(bus='SESSION', enable_fds=False)[source]

Open a D-Bus ‘router’ to send and receive messages.

Use as a context manager:

with open_dbus_router() as router:
    ...

On leaving the with block, the connection will be closed.

Parameters:
  • bus (str) – ‘SESSION’ or ‘SYSTEM’ or a supported address.
  • enable_fds (bool) – Whether to enable passing file descriptors.
Returns:

DBusRouter

class jeepney.io.threading.DBusRouter(conn: jeepney.io.threading.DBusConnection)[source]

A client D-Bus connection which can wait for replies.

This runs a separate receiver thread and dispatches received messages.

It’s possible to wrap a DBusConnection in a router temporarily. Using the connection directly while it is wrapped is not supported, but you can use it again after the router is closed.

send(message, *, serial=None)[source]

Serialise and send a Message object

send_and_get_reply(msg: jeepney.low_level.Message, *, timeout=None) → jeepney.low_level.Message[source]

Send a method call message, wait for and return a reply

filter(rule, *, queue: Optional[queue.Queue] = None, bufsize=1)[source]

Create a filter for incoming messages

Usage:

with router.filter(rule) as queue:
    matching_msg = queue.get()
Parameters:
  • rule (jeepney.MatchRule) – Catch messages matching this rule
  • queue (queue.Queue) – Matched messages will be added to this
  • bufsize (int) – If no queue is passed in, create one with this size
close()[source]

Close this router

This does not close the underlying connection.

Leaving the with block will also close the router.

class jeepney.io.threading.Proxy(msggen, router, *, timeout=None)[source]

A blocking proxy for calling D-Bus methods via a DBusRouter.

You can call methods on the proxy object, such as bus_proxy.Hello() to make a method call over D-Bus and wait for a reply. It will either return a tuple of returned data, or raise DBusErrorResponse. The methods available are defined by the message generator you wrap.

You can set a time limit on a call by passing _timeout= in the method call, or set a default when creating the proxy. The _timeout argument is not passed to the message generator. All timeouts are in seconds, and TimeoutErrror is raised if it expires before a reply arrives.

Parameters:
  • msggen – A message generator object
  • router (DBusRouter) – Router to send and receive messages
  • timeout (float) – Default seconds to wait for a reply, or None for no limit
jeepney.io.threading.open_dbus_connection(bus='SESSION', enable_fds=False, auth_timeout=1.0)[source]

Open a plain D-Bus connection

D-Bus has an authentication step before sending or receiving messages. This takes < 1 ms in normal operation, but there is a timeout so that client code won’t get stuck if the server doesn’t reply. auth_timeout configures this timeout in seconds.

Returns:DBusConnection
class jeepney.io.threading.DBusConnection(sock: socket.socket, enable_fds=False)[source]
send(message: jeepney.low_level.Message, serial=None)[source]

Serialise and send a Message object

receive(*, timeout=None) → jeepney.low_level.Message[source]

Return the next available message from the connection

If the data is ready, this will return immediately, even if timeout<=0. Otherwise, it will wait for up to timeout seconds, or indefinitely if timeout is None. If no message comes in time, it raises TimeoutError.

If the connection is closed from another thread, this will raise ReceiveStopped.

close()[source]

Close the connection