Re: Event-loop-friendly receive_message() call

Lawrence D'Oliveiro <ldo-kC51rjc0cqs1dNLGKZg6taU/[email protected]>
Newsgroups gmane.comp.freedesktop.dbus
Organization Geek Central
Message-ID <[email protected]>
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>.
_______________________________________________
dbus mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dbus
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.