Making asynchronous calls
simon.mcvittie at collabora.co.uk
Thu Feb 7 08:06:03 PST 2008
-----BEGIN PGP SIGNED MESSAGE-----
On Thu, 07 Feb 2008 at 15:06:47 +0000, Robert Rawlins wrote:
> def timeout_func():
> #Call To Web Service Goes Here
> return False
> gobject.timeout_add(500, timeout_func)
> Does that look correct? or am I missing something?
What you're missing is that I'm using timeout_add as a silly fake
example of a way to get a callback called later. What you actually want
to do is to make an async request into the web services library, i.e.
arrange for the reply_cb (or error_cb) to be called later *by the web
services library* (or by some of your code that's run by the web
So it'd look something like:
webservices.call(foo, bar, onCompleted=lambda x: ok_all_done(x))
where webservices.call is an asynchronous API provided by the library
you're calling into.
(The Python standard library's xmlrpclib module, for instance, can't be
used like this - it only has a synchronous (blocking) API.)
For instance, if your web-services calls were being made using Twisted
you'd do an async call that returned a Deferred, and then do something
Then your error_cb or reply_cb would run at some later point when
Twisted returned to the main loop.
-----BEGIN PGP SIGNATURE-----
-----END PGP SIGNATURE-----
More information about the dbus