Making asynchronous calls

Robert Rawlins robert_rawlins at hotmail.com
Thu Feb 7 05:41:50 PST 2008


Simon McVittie Wrote:> 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:
 
I suspect you might be right with this, I just copied the service concept from some code I found in the examples folder of the source, however, it might not be async, I notice they gave an async example of a client along with a standard one, but no apparant async example of a service.
 
Looking at the code example you gave below, I notice a few things which are different from my service, namely the references to the async_callbacks=('reply_cb', 'error_cb')) This is something which isn't currently implemented in my service, also, My current function doesn't return False, I have it return the results of the function, opposed to passing it to the return_cb or error_cb methods.
 
Are you able to give me some examples of return_cf and error_cf functions and how they should be placed within the service? I would really appreciate that.> The underlying framework you're using for the web-service requests will> have to be able to run asynchronously too.
 
This is also a great point, and at the moment I cant guarantee that it will be, however, I'm confident that it is, I've used other methods on it async style which send back signals which I listen for. I just want to get my own service to a point where I can be sure its Async, and if I'm still having problems then look at some threading choices.
 
Thanks Simon, if you wouldn't mind showing me an example of how to implement callbacks in the service I would owe you a beer.
 
Robert



> Date: Thu, 7 Feb 2008 13:26:17 +0000> From: simon.mcvittie at collabora.co.uk> To: dbus at lists.freedesktop.org> Subject: Re: Making asynchronous calls> > -----BEGIN PGP SIGNED MESSAGE-----> Hash: SHA1> > 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:> > @dbus.service.method('com.example.Crack', in_signature='s',> out_signature='s',> async_callbacks=('reply_cb', 'error_cb'))> def MakeHTTPRequest(self, url, reply_cb, error_cb):> # this is a fake implementation that pretends the server replied> # after 15 seconds> def timeout_func():> reply_cb('404 Not Found\r\n')> return False> gobject.timeout_add(15000, timeout_func)> > 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.> > Simon> -----BEGIN PGP SIGNATURE-----> > iD8DBQFHqwb5WSc8zVUw7HYRApnUAKCeXobLHciESHURQZNGDTtWXRetbwCghyIU> Cyy/kXhWn22wqtIE3LTHgZU=> =M8EW> -----END PGP SIGNATURE-----> _______________________________________________> dbus mailing list> dbus at lists.freedesktop.org> http://lists.freedesktop.org/mailman/listinfo/dbus
_________________________________________________________________
Free games, great prizes - get gaming at Gamesbox. 
http://www.searchgamesbox.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20080207/ed139de3/attachment-0001.htm 


More information about the dbus mailing list