<br><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I'm not sure that I understood that. Could you provide a simple test case that<br>
should work, but doesn't, and describe what it ought to do?</blockquote><div><br>Ok, this is a little ugly, but it's as simple as I can get it...<br><br>tsuraan@localhost ~/test/python/dbus/blocking $ cat Slow.py
<br>import gobject<br>import dbus<br>import dbus.service<br>import dbus.glib<br>import time<br><br>class Slow(dbus.service.Object):<br> def __init__(self):<br> bus = dbus.SystemBus()<br> bus_name = dbus.service.BusName
("com.example.Slow", bus)<br><br> super(Slow, self).__init__(bus_name, "/Object")<br><br> @dbus.service.method("com.example.Slow")<br> def sfunction(self):<br> # Sleep a while, but not long enough for dbus timeout...
<br> time.sleep(5)<br> return 'Hi!'<br><br><br>if __name__ == "__main__":<br> gobject.threads_init()<br> dbus.glib.init_threads()<br><br> s = Slow()<br> gobject.MainLoop().run()<br><br>tsuraan@localhost
~/test/python/dbus/blocking $ cat Caller.py <br>import gobject<br>import dbus<br>import dbus.service<br>import dbus.glib<br>import time<br>import threading<br><br>class Caller(dbus.service.Object):<br> def __init__(self):
<br> self.bus = dbus.SystemBus()<br> bus_name = dbus.service.BusName("com.example.Caller", self.bus)<br><br> super(Caller, self).__init__(bus_name, "/Object")<br><br> @dbus.service.method("
com.example.Caller")<br> def cfunction(self):<br> obj = self.bus.get_object("com.example.Slow", "/Object")<br> thread = threading.Thread(target=obj.sfunction)<br> thread.start()<br> # Sleep for a moment to make the context switch happen
<br> time.sleep(1)<br> return 'done'<br> <br><br><br>if __name__ == "__main__":<br> gobject.threads_init()<br> dbus.glib.init_threads()<br><br> c = Caller()<br> gobject.MainLoop().run()<br><br>
tsuraan@localhost ~/test/python/dbus/blocking $ cat test.py <br>import dbus<br>import dbus.glib<br>import time<br><br>bus = dbus.SystemBus()<br>obj = bus.get_object("com.example.Caller", "/Object")<br>
start = time.time()<br>obj.cfunction()<br>print 'call took', time.time()-start, 'seconds'<br><br></div><br>tsuraan@localhost ~/test/python/dbus/blocking $ python Slow.py & python Caller.py &<br>[1] 8636
<br>[2] 8637<br>tsuraan@localhost ~/test/python/dbus/blocking $ python test.py <br>call took 5.00829911232 seconds<br><br><br>One would expect the call to have taken about one second, but instead it takes five. It looks like the first dbus method in Caller cannot return until its call has completed. Is that a bug, or is that a part of the spec? Or, is this a glib problem, and I should ask them about it? It doesn't really look like glib and python threads play very nicely together, so maybe that's the problem.
<br></div>