[Uwsgi] Python Threading and Locks__python

Source: Internet
Author: User

Http://lists.unbit.it/pipermail/uwsgi/2012-April/004089.html


> 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 > then run in Uwsgi it hangs on the lock.  I know the lock has been released > because I am writing to the "Log on" line before and "after the" > line
The code that releases the lock. > > This is me 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 = Ed  Pod.uwsgi > callable = app > socket = 127.0.0.1:6000 > Enable-threads > > Does anyone have any ideas or can
Point me to some documentation around > I > 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 would spawn the thread and then it fork ().

In the new process, the thread are no more.

The best way to solve it's in starting the thread of the fork (), using the Uwsgi.post_fork_hook. Another solution is in putting your stack in "lazy" mode. That means your The app is completely the loaded only for each fork (). Simply Add lazy = true for that setup.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.