You’ll probably want to use the uWSGI spooler or some other queueing mechanism 
for things like sending mails in the background.

- Aarni

From: [email protected] [mailto:[email protected]] On 
Behalf Of Pasithee Jupiter
Sent: Monday, January 27, 2014 10:13 AM
To: [email protected]
Subject: [uWSGI] background thread

Hi All

I know it was asked a lot but after hours of searching and trying several 
posts, I couldn't find any solution to create a "long running" thread.

The problem is, that my thread stops working, as soon as the client gets a 
response from the server.

So what I have is the following:

  *   uwsgi == 1.9.17.1-debian
  *   nginx == 1.4.4 (Ubuntu)

class Mailer(object):
    self._threads = []

    def send(self):
         ...
         thread = Thread(target=self._send, args=(email_addr, msg.as_string()))
         thread.daemon = True
         thread.start()
         self._threads.append(thread)
         ...

    def join(self):
        return [t.join(5) for t in self._threads]

    def __del__(self):
        self.join()


which should send out some mails. When I call the function directly it works. 
So the error could not be inside the _send() function.

I start my web application using the emperor

exec $BINPATH --emperor /opt/www/vassals/ --pidfile /var/run/uwsgi/emperor.pid 
--stats 127.0.0.1:9191<http://127.0.0.1:9191> --logto $LOGTO

and the following xml

<uwsgi>
                      <vhost />
                      <plugins>python</plugins>
                      <master />
                      <vacuum />
                      <processes>2</processes>
                      <enable-threads />
                      <lazy />
                      <chmod-socket>666</chmod-socket>
                      <socket>/tmp/uwsgi.%n.webapp.sock</socket>
                      <uid>www-data</uid>
                      <gid>www-data</gid>
                      <virtualenv>/opt/virtualenv/%n</virtualenv>
                      <pythonpath>%d../%n</pythonpath>
                      <chdir>%d../%n</chdir>
                      <module>scripts.%n_wsgi</module>
                      <buffer-size>65535</buffer-size>
                      <pidfile>/var/run/uwsgi/%n.pid</pidfile>
                      <touch-reload>%d../%n</touch-reload>
                      <daemonize>/var/log/uwsgi/%n.log</daemonize>
</uwsgi>


Does anyone has an idea?

_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to