List Info

Thread: Time.sleep & HttpResponse




Time.sleep & HttpResponse
user name
2007-12-16 18:14:32
Hi,

I'm trying to use Time.sleep function on printing, here is
the code:

def sleep(request):
	res = HttpResponse()
	res.write("hello")
	time.sleep(3)
	res.write("hello");
	return res

But it doesn't work (Page waits 3 seconds and prints
"hellohello"),
how can i solve this problem? If we can solve this problem,
i think
that we can create comet applications easily...

Thanks
Azer
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Time.sleep & HttpResponse
user name
2007-12-16 19:35:13
If you put /print "hello"/, the server should
print it with given
delay (on the server side).
I think that you should use JS/AJAX to update the page after
it is
sent to the user (script on the user side).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Time.sleep & HttpResponse
user name
2007-12-17 05:22:16
Comet:http:/
/www.google.com/search?hl=en&q=comet
reverse ajax: http
://www.google.com/search?hl=en&q=reverse ajax

On Dec 17, 3:35 am, l5x <mail.loo...gmail.com> wrote:
> If you put /print "hello"/, the server should
print it with given
> delay (on the server side).
> I think that you should use JS/AJAX to update the page
after it is
> sent to the user (script on the user side).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Time.sleep & HttpResponse
user name
2007-12-17 06:09:27
"I propose to design and implement an API to make Comet
behavior
available to Django applications."
http://hosted.
corp.it/django/full.html
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Time.sleep & HttpResponse
country flaguser name
Colombia
2007-12-17 06:10:49
l5x wrote:
> "I propose to design and implement an API to make
Comet behavior
> available to Django applications."
> http://hosted.
corp.it/django/full.html
> >
>
>   
Good Idea 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Time.sleep & HttpResponse
country flaguser name
Australia
2007-12-17 06:41:00

On Sun, 2007-12-16 at 16:14 -0800, azer wrote:
> Hi,
> 
> I'm trying to use Time.sleep function on printing, here
is the code:
> 
> def sleep(request):
> 	res = HttpResponse()
> 	res.write("hello")
> 	time.sleep(3)
> 	res.write("hello");
> 	return res
> 
> But it doesn't work (Page waits 3 seconds and prints
"hellohello"),
> how can i solve this problem? If we can solve this
problem, i think
> that we can create comet applications easily...

Based on your later, slightly cryptic reply in this thread,
I gather you
are hoping that HttpResponse is acting as a streamable pipe
back to the
browser. This isn't correct. You create an HttpResponse
instance and
when you return from your view, Django will send all of the
content back
to the user in one go. Nothing happens until you return from
the view.

If you want to implement something streamable for Comet
purposes, you'll
need to implement your own, slightly lower-level interaction
with the
webserver and the downstream client. Django doesn't have
built-in
support for that.

Regards,
Malcolm

-- 
Why be difficult when, with a little bit of effort, you
could be
impossible. 
http://www.pointy-s
tick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Time.sleep & HttpResponse
country flaguser name
Australia
2007-12-17 06:43:41

On Mon, 2007-12-17 at 07:10 -0500, Ariel Calzada wrote:
> l5x wrote:
> > "I propose to design and implement an API to
make Comet behavior
> > available to Django applications."
> > http://hosted.
corp.it/django/full.html
> > >
> >
> >   
> Good Idea 

Keep in mind that that link was a proposal for the recently
completed
Google Summer of Code. It wasn't one of the projects we
accepted for
this year.

Regards,
Malcolm

-- 
Everything is _not_ based on faith... take my word for it. 
http://www.pointy-s
tick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Time.sleep & HttpResponse
country flaguser name
Finland
2007-12-23 04:12:01
Malcolm Tredinnick wrote
> Based on your later, slightly cryptic reply in this
thread, I gather you
> are hoping that HttpResponse is acting as a streamable
pipe back to the
> browser. This isn't correct. You create an HttpResponse
instance and
> when you return from your view, Django will send all of
the content back
> to the user in one go. Nothing happens until you return
from the view.
>   
There is one way: using a generator you can simulate
"streaming". The 
code below actually sends two chunks of response data in the
TCP/IP 
stream at 1 second interval.

def example_generator():
    yield 'foo'
    time.sleep(1)
    yield 'bar'

def my_view():
    return HttpResponse(dummy_generator())





--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Time.sleep & HttpResponse
country flaguser name
Australia
2007-12-24 02:40:46

On Sun, 2007-12-23 at 12:12 +0200, Matti Haavikko wrote:
> Malcolm Tredinnick wrote
> > Based on your later, slightly cryptic reply in
this thread, I gather you
> > are hoping that HttpResponse is acting as a
streamable pipe back to the
> > browser. This isn't correct. You create an
HttpResponse instance and
> > when you return from your view, Django will send
all of the content back
> > to the user in one go. Nothing happens until you
return from the view.
> >   
> There is one way: using a generator you can simulate
"streaming". The 
> code below actually sends two chunks of response data
in the TCP/IP 
> stream at 1 second interval.
> 
> def example_generator():
>     yield 'foo'
>     time.sleep(1)
>     yield 'bar'
> 
> def my_view():
>     return HttpResponse(dummy_generator())

Definitely not recommended, because it won't work as you
expect a lot of
the time. There are a large number of middlewares (including
many that
come with Django's core) that cannot on-demand production.
This led to
lots of problems when we tried to change template rendering
to use
iteration earlier this year.

At some point we need to fix HttpResponse.__init__ so that
it
immediately consumes any iterator is passed and stores the
content to
avoid subtle bugs in this area.

Regards,
Malcolm

-- 
Experience is something you don't get until just after you
need it. 
http://www.pointy-s
tick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-9]

about | contact  Other archives ( Real Estate discussion Medical topics )