python bindings & gmainloop

Sean Meiners sean.meiners at linspireinc.com
Thu Sep 15 15:01:19 PDT 2005


On Wednesday 14 September 2005 04:08 pm, John (J5) Palmieri wrote:
> On Wed, 2005-09-14 at 15:11 -0700, Sean Meiners wrote:
> > Is there any way, at all, to use the python bindings without the
> > gmainloop? The reason I as is that I'm writing a couple of apps in
> > pykde/qt and find that entering the gmainloop prevents the python
> > interpreter from servicing any other threads (both python threads and
> > QThreads).  I've worked around this issue temporarily by creating a
> > function that sleeps for a short time and passing it to
> > gobject.timeout_add.  This seems to give enough time back to the
> > interpreter to service other threads, but it just doesn't feel like the
> > right way to go about it (time-slicing is the kernel's job).  I would
> > much prefer to use a python thread (or the Qt event loop if necessary) to
> > service the dbus signal receivers. Is this currently possible?
>
> For sending you can just use blocking calls but for receiving you need
> to have a main loop that is integrated with D-Bus.  gmainloop shouldn't
> block other threads though.  Can you try making a loop without using
> dbus and see if that also causes the problem in which case it is a bug
> in PyGTK?  If it doesn't then the Pyrex bindings could be holding onto
> the GIL for too long.	

Ok, so I finally figured out how to get gmainloop to play nice with other 
threads, only to expose an even more interesting problem.  When my test 
script is run (attached) it causes a 'Fatal Python error: PyThreadState_Get: 
no current thread' as soon as the gmainloop is entered, but only if threading 
has been initialized and you actually connect to a bus (system or session, it 
makes no difference). Now here's the really interesting part: it all works 
fine if I undo your EmptyMessage patch (diff attached).

>
> Another point is I recently split out the GLib stuff so anyone is free
> to implement another main loop adapter.  Look at the dbus.py and
> dbus_glib_bindings.pyx files to see how this is done.  Patches are
> welcome.

I poked around in there, but it calls dbus_connection_setup_with_g_main which 
does all the heavy lifting of gmainloop integration which in turn relies on 
several dbus_connection_set_* functions that aren't exported by the python 
bindings as far as I can tell. So there doesn't seem to be a way to replace 
the gmainloop in the python bindings without direct modification. I was 
hoping to be able to do the gmainloop replacement in my application and leave 
the bindings to you ;) .

>
> Oh also you need to initialize threading in both GTK and DBus.

-- 
Sean Meiners
sean.meiners at linspireinc.com


Perl - $Just @when->$you ${thought} s/yn/tax/ &couldn\'t %get $worse;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dbus-thread.py
Type: application/x-python
Size: 506 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/dbus/attachments/20050915/0275ed6c/dbus-thread.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dont_use_emptymessage.diff
Type: text/x-diff
Size: 1592 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/dbus/attachments/20050915/0275ed6c/dont_use_emptymessage.bin


More information about the dbus mailing list