Signals in Python without glib

Justin Mazzola Paluska jmp at MIT.EDU
Tue Aug 1 23:36:13 PDT 2006


On Thu, Jul 27, 2006 at 05:53:16PM +0800, Justin Mazzola Paluska wrote:
> I added a read_write_dispatch(timeout) method to the low-level
> DBUSConnection bindings and then wrote the Bus.generic_main_loop()
> function.  Please see the attached patch.  It seems to be working on
> my machine with Python 2.4.4c0 and D-BUS 0.62.

Maybe I spoke too quickly.  I'm trying to use the code (with the
patch) to make a dumb mainloop in a thread, then have another thread
make both blocking and signal requests as it needs.  Signals seem to
work fine, but function calls do not.

My mainloop essentially calls the generic_main_loop function of my
patch, which itself is essentially:

        while self._connection.read_write_dispatch():
            pass
        return

Once this while loop starts up, I can no longer make blocking function
calls in another thread.  Instead, CPU usage shoots up to 100%.  I
attached to the process with gdb and it looks the mainloop thread is
blocked on poll and the request thread is taking up all of the
processor time.  When I step through the code using gdb, it looks like
the request thread is stuck in a loop:

    #0  0xa7ba2f30 in dbus_timeout_get_enabled () from
     /usr/lib/libdbus-1.so.2
    #1  0xa7b8fe74 in dbus_connection_set_watch_functions ()
       from /usr/lib/libdbus-1.so.2
    #2  0xa7b90b1c in dbus_connection_flush () from
     /usr/lib/libdbus-1.so.2
    #3  0xa7b90cc9 in dbus_connection_flush () from
     /usr/lib/libdbus-1.so.2
    #4  0xa7b9df9d in dbus_pending_call_block () from
     /usr/lib/libdbus-1.so.2
    #5  0xa7b911d9 in dbus_connection_send_with_reply_and_block ()
       from /usr/lib/libdbus-1.so.2
    #6  0xa7bebc80 in
     __pyx_f_13dbus_bindings_10Connection_send_with_reply_and_block
     (__pyx_v_self=0xa792d80c, __pyx_args=0xa7d3912c, __pyx_kwds=0x0)
        at dbus/dbus_bindings.c:3090

It repeatedly returns from dbus_timeout_get_enabled to
dbus_connection_set_watch_functions and then jumps back into
dbus_timeout_get_enabled.

The two attached Python files show the problem I'm having.  The
hello-server.py it taken directly from the D-Bus tutorial; lockup.py
causes problems.

I'd like to get to the bottom of this so that I can improve the Python
generic_main_loop.

Thanks,
	--Justin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hello-server.py
Type: text/x-python
Size: 644 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/dbus/attachments/20060802/ca3a5129/hello-server.py
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lockup.py
Type: text/x-python
Size: 610 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/dbus/attachments/20060802/ca3a5129/lockup.py


More information about the dbus mailing list