Date: Mon, 23 Apr 2012 07:55:59 +0200 > From: "Roberto De Ioris" <[email protected]> > To: "uWSGI developers and users list" <[email protected]> > Subject: Re: [uWSGI] Python threading and locks > Message-ID: > <[email protected]> > Content-Type: text/plain;charset=utf-8 > > > > I have a web application written in Flask. At startup it spawns a > > background thread and waits on a threading.Event for the background > thread > > to initialise before continuing. It works fine when run outside uwsgi, > but > > when run in uwsgi it hangs on the lock. I know the lock has been released > > because I am writing to the log on the line before and the line after the > > line of code that releases the lock. > > > > Here is my config file, I am running uwsgi in Emperor mode: > > > > [uwsgi] > > master = true > > processes = 1 > > uid=edpod > > gid=edpod > > virtualenv = /host/sites/edpod > > pythonpath = /host/sites/edpod > > module = Edpod.uwsgi > > callable = app > > socket = 127.0.0.1:6000 > > enable-threads > > > > Does anyone have any ideas or can point me to some documentation around > > how > > threading works in uwsgi. > > > > > Hi Richard, it is not a threading problem, but a fork()-related one. > > I suppose you are starting your thread in the application entry point (the > file Edpod/uwsgi.py). The master will spawn the thread and then it fork(). > > In the new process, the thread is no more. > > The best way to solve it is in starting the thread only after the fork(), > using the uwsgi.post_fork_hook. > > Another solution is in putting your stack in "lazy" mode. That means your > app is completely loaded only after each fork(). Simply add lazy = true > for that setup. >
Thanks for the suggestion. Problem was in fact my bad - works on python2.6 but not 2.7 - Interface for threading.Event.wait() had changed between these version. I am now having a problem with forking, or at least a call to subprocess.call() which hangs indefinitely. Again this is in the background thread that runs at program startup. e.g. (I'm not really running date, that is just a trivial program that should run) subprocess.call(['/bin/date'], close_fds=True) Are there any options or other tricks to let the worker process fork. [uwsgi] master = true processes = 1 uid=edpod gid=edpod virtualenv = /host/sites/edpod pythonpath = /host/sites/edpod module = StellarLibrary.uwsgi callable = app socket = 127.0.0.1:6000 close-on-exec = true enable-threads = true lazy = true
_______________________________________________ uWSGI mailing list [email protected] http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
