Event-loop-friendly receive_message() call
Lawrence D'Oliveiro
ldo at geek-central.gen.nz
Fri Feb 2 07:31:09 UTC 2018
On Sun, 21 Jan 2018 14:23:21 +1300, I wrote:
> I have added a new feature to DBussy <https://github.com/ldo/dbussy>,
> my Python binding for libdbus, namely a call to read incoming messages
> from a connection in an event-loop-friendly way, with an optional
> timeout.
I have taken this further, by also allowing the reception of messages in
an “async for” loop:
async for message in conn.iter_messages_async() :
... process message ..
#end for
You can optionally specify “stop_on” and “timeout” arguments to the
iter_messages_async() call. “stop_on” is a set of values from the
STOP_ON.xxx enumeration to specify conditions for automatically
stopping the loop. (Of course, you can always explicitly break out of
it, or raise an exception.) By default you get None instead of a
Message object if you specify a timeout and no message is received in
time; but you can include STOP_ON.TIMEOUT in the stop_on set to have
the loop terminate instead.
I have added an alternative version of the “signal_listener_queued”
example script, called “signal_listener_queued_alt”, which uses this
call, in <https://github.com/ldo/dbussy_examples>.
More information about the dbus
mailing list