Blocking I/O

This is a good option for simple scripts, where you don’t need to do anything else while waiting for a D-Bus reply. If you will use D-Bus for multiple threads, or you want a nicer way to wait for signals, see Blocking I/O with threads.

jeepney.io.blocking.open_dbus_connection(bus='SESSION', enable_fds=False, auth_timeout=1.0) → jeepney.io.blocking.DBusConnection[source]

Connect to a D-Bus message bus

Pass enable_fds=True to allow sending & receiving file descriptors. An error will be raised if the bus does not allow this. For simplicity, it’s advisable to leave this disabled unless you need it.

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.

class jeepney.io.blocking.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.

send_and_get_reply(message, *, timeout=None, unwrap=None)[source]

Send a message, wait for the reply and return it

Filters are applied to other messages received before the reply - see add_filter().

recv_messages(*, timeout=None)[source]

Receive one message and apply filters

See filter(). Returns nothing.

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

Create a filter for incoming messages

Usage:

with conn.filter(rule) as matches:
    # matches is a deque containing matched messages
    matching_msg = conn.recv_until_filtered(matches)
Parameters:
  • rule (jeepney.MatchRule) – Catch messages matching this rule
  • queue (collections.deque) – Matched messages will be added to this
  • bufsize (int) – If no deque is passed in, create one with this size
recv_until_filtered(queue, *, timeout=None) → jeepney.low_level.Message[source]

Process incoming messages until one is filtered into queue

Pops the message from queue and returns it, or raises TimeoutError if the optional timeout expires. Without a timeout, this is equivalent to:

while len(queue) == 0:
    conn.recv_messages()
return queue.popleft()

In the other I/O modules, there is no need for this, because messages are placed in queues by a separate task.

Parameters:
close()

Close the connection

Using with open_dbus_connection() will also close the connection on exiting the block.

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

A blocking proxy for calling D-Bus methods

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
  • connection (DBusConnection) – Connection to send and receive messages
  • timeout (float) – Default seconds to wait for a reply, or None for no limit