I just gave this a try and it didn't give me the result I was
expecting. The code I tried is:
def index(self):
req = request.current_obj()
def long_func():
env = req.environ
yield 'I am starting now'
#simulate a very long process
for i in range(10000):
print i
yield 'I should be finishing now'
res = Response()
res.content = long_func()
return res
I know that this really does not do anything, I am just trying to get
the use-case to work. What I expected to see in the browser was first
the "I am starting now" statement, followed by by the print stuff in
the cmd window followed by the last statement being sent to the
browser. Instead it looks like either its all being sent at once, or
the browser is waiting for the page to finish before anything gets
rendered. Do you know of any way to test to see which is it?
Jose
Ben Bangert wrote:
> On Aug 15, 2006, at 11:07 PM, jose wrote:
>
> > Is it possible to send intermediate content to a browser with pylons?
> > the use-case is if I have a long process I would like to send some
> > content to the browser, run my long process and then send the rest of
> > the content in real-time. Currently an action waits for the must
> > return the Response, meaning that all the content is sent all at once
> > rather then incremental.
> > Thanks for any and all help
>
>
> You'll want to return a generator as your response like so:
>
> def action(self):
> req = request.current_obj()
> def long_func():
> env = req.environ
> yield "some content"
> # do something that takes awhile
> yield "more content"
> resp = Response()
> resp.content = long_func()
> return resp
>
> Note that you need to bring special vars like request, c, g, and
> session into scope for the generator closure so that they'll be
> available when the generator is used for the response.
>
> Hopefully that makes sense?
>
> HTH,
> Ben
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss
-~----------~----~----~----~------~----~------~--~---