Making asynchronous calls
simon.mcvittie at collabora.co.uk
Thu Feb 7 05:26:17 PST 2008
-----BEGIN PGP SIGNED MESSAGE-----
On Thu, 07 Feb 2008 at 12:13:54 +0000, Robert Rawlins wrote:
> When I run this client code it prints "Made Calls" almost immediately and then over the next 10 seconds or so the service appears to call my callbacks and print the results of the calls to the screen, exactly as I would expect it too. However, If I change that first call to a web address I know doesn't work properly and will return really slowly then I don't get any callbacks called until the first web service call has timed out, then they are both called nice and quickly.
> Do you see what I mean? My service appears to be quing my requests, which means that if one request runs slowly then it clogs up the queue.
I suspect your service implementation is at fault here. What ought to
happen is that the binding calls your service implementations on a queue
basis, but the service implementations return almost immediately:
def MakeHTTPRequest(self, url, reply_cb, error_cb):
# this is a fake implementation that pretends the server replied
# after 15 seconds
reply_cb('404 Not Found\r\n')
The underlying framework you're using for the web-service requests will
have to be able to run asynchronously too.
If it can't, you could hack up some solution where the D-Bus method
implementation fires off a worker thread that makes a synchronous
request, the result from that thread is communicated back to the
main thread somehow (perhaps with a pipe-to-self), and the main thread
responds by calling the reply_cb.
-----BEGIN PGP SIGNATURE-----
-----END PGP SIGNATURE-----
More information about the dbus