On 2013-02-27, at 18:47 , Stefano Tranquillini wrote:

> Hi, thank you for the answer.
> basically what i've to do is to iterate the same operation for a bunch of
> user (e.g. send an email).
> i've around 200 users and each mail takes 2 seconds.
> so 400 seconds in total and the server goes in timeout. Have to wait 400
> seconds on a blank page is not really nice as well.
> 
> what i want to do is to stream out to a page an info that a new email was
> sent. This will avoid the timeout (i guess) and i can keep track of the
> job.

This kind of stuff is generally done asynchronously, dispatching the
sending to some sort of queue[0] to be executed either through a cronjob
or through a dedicated worker (*not* a WSGI/Django handler) waiting for
any mail to send.

Notifications, if any, are provided separately (e.g. by reloading a
"status" page every 10~15~30s or so; by using a javascript widget
polling the same kind of "status" endpoint or by using more "push"-y
async techniques). If you want notifications you probably want to use
a queue/worker system (rather than cronjobs) so they can get started
immediately and provide feedback. Something like Celery[2] for instance.

Sending email (or any other kind of very long operation) within the HTTP
request is pretty much always A Bad Idea: it ties up resources (e.g.
HTTP/WSGI workers, database transactions) better used serving requests
to users and tends to make the code more gnarly and less maintainable.

As far as I've seen anyway.

[0] For instance Pinax's Django Mailer[1] has an in-request part which
    shoves mails to send in the DB, and a management command to execute via
    e.g. a cronjob which does the actual sending
[1] https://github.com/pinax/django-mailer
[2] celeryproject.org

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to