[dbus][python] Method dispatch also single-threaded?
tsuraan
tsuraan at gmail.com
Mon Jan 22 13:12:15 PST 2007
Is it possible for a single dbus-python exported object to dispatch multiple
methods at once? I have one object that exports a few (slow) methods, and
in another program I quickly call them (asynchronously). The slow object is
printing at the beginning and end of each method call, so it's clear that
the methods aren't being run simultaneously. Instead, each waits for the
one before it to finish. Is there some way to get the mainloop to dispatch
methods simultaneously?
Also, to make sure there wasn't a bug in the async calls, I tried doing all
three methods at once in different instances of python, and I get the same
problem. "Screenshot" follows:
tsuraan at localhost ~/test/python/dbus/moreblocking $ cat Slow.py
import gobject
import dbus
import dbus.service
import dbus.glib
import time
class Slow(dbus.service.Object):
def __init__(self):
bus = dbus.SystemBus()
bus_name = dbus.service.BusName("com.example.Slow", bus)
super(Slow, self).__init__(bus_name, "/Object")
@dbus.service.method("com.example.Slow")
def function1(self):
print 'starting function1'
time.sleep(5)
print 'done with function1'
return 1
@dbus.service.method("com.example.Slow")
def function2(self):
print 'starting function2'
time.sleep(5)
print 'done with function2'
return 2
@dbus.service.method("com.example.Slow")
def function3(self):
print 'starting function3'
time.sleep(5)
print 'done with function3'
return 3
if __name__ == "__main__":
gobject.threads_init()
dbus.glib.init_threads()
s = Slow()
gobject.MainLoop().run()
tsuraan at localhost ~/test/python/dbus/moreblocking $ cat test.py
import gobject
import dbus
import dbus.glib
import time
def noop(*args):
pass
bus = dbus.SystemBus()
obj = bus.get_object("com.example.Slow", "/Object")
obj.function1(reply_handler=noop, error_handler=noop)
obj.function2(reply_handler=noop, error_handler=noop)
obj.function3(reply_handler=noop, error_handler=noop)
gobject.MainLoop().run()
tsuraan at localhost ~/test/python/dbus/moreblocking $ python Slow.py & sleep 1
&& python test.py
[1] 18460
starting function1
done with function1
starting function2
done with function2
starting function3
done with function3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20070122/d75ca7d7/attachment.html
More information about the dbus
mailing list