Rol El schrieb:
> Hello,
>
> I have the same exact question about how to use asynchronous calls in
> TG.
>
> I have a library which talks to a remote server, and it might take a
> few millisecs to never i guess.. The way i talk to it is thru a
> callback.
>
> The page request comes in the controller.. then I call
> GetMeTheData(myCallBack. arg1, arg2)... this function immediately
> returns. Then i have to wait for the "myCallBack" to get the data
> before I return from the controller. Anyone have ideas on how to do
> this thru TG?
How is that callback invoked? Is there a thread spawned to fetch the data?
Whatever happens, just put the data into the session via myCallback. You
should be able to do it like this:
class Callback(object):
def __init__(self):
# get the current users session, so we have it when invoked
from a different thread!
self.session = cherrypy.session
def __call__(self, *args, **kwargs):
self.session['GetMeTheDataResults', (args, kwargs))
Now if you want your user to be notified about the arrived data
immediately - that is the tricky part, either you do a frequent polling
triggered by javascript, or you take a look at server push technologies
like comet - but AFAIK that is not a really
good option for TG right now.
Diez
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---