Signals in Python without glib

Havoc Pennington hp at redhat.com
Wed Jul 26 07:35:42 PDT 2006


Justin Mazzola Paluska wrote:
> On Mon, Jul 24, 2006 at 03:24:18PM -0400, John (J5) Palmieri wrote:
>> The python bindings can not receive signals without the glib mainloop 
>> and we don't currently wrap the methods needed to update and dispatch 
>> (you need to update as well as dispatch).  Patches welcome.
> 
> What are the update methods?  Looking at dbus_connection_dispatch in
> dbus-connection.c:3472
> (http://dbus.freedesktop.org/doc/api/html/dbus-connection_8c-source.html#l03472),
> it looks like the dispatch method inherently makes updates, but I
> don't think that's what you were referring to.
> 
> I've pulled the most recent version of the Python bindings out of git
> and compiled them against my system DBUS (0.62), so if you can send me
> pointers on where to start adding signal handling for Python, I'll
> start hacking.
> 

There are basically two things that need doing:
  - reading and writing data to the socket, which either drains the
    outgoing message queue or fills the incoming message queue
    (this is usually called "read_write" in the API)
  - running handlers for the incoming message queue and removing
    handled messages (this is called "dispatch")

If you don't want to block on the dbus socket (want to use your own main 
loop), you need to set things up so you call read_write when needed; 
this means adding "timeout" and "watch" handlers.

If you do block on the dbus socket, you are just always calling 
read_write (they can block if there's no work to do), so no 
timeout/watch handlers are required.

Whether you block or not, after reading and writing you need to dispatch 
in case there are now messages in the incoming queue. If you fail to 
dispatch, then you won't see those messages.

Dispatching is in some sense optional; you can also manually drain the 
message queue with dbus_connection_pop_message(). But this is only 
useful if you know you are the sole user of the DBusConnection object, 
since it does not run handlers others may have registered.

Havoc



More information about the dbus mailing list