Search code examples
pythonuwsgi

How does python application thread work with UWSGI?


I have a python flask application running behind uwsgi. Below is the script I use to launch my application. As you can see that there is --enable-threads flag in the script. Based on uwsgi document, it says: If you want to maintain Python threads support without starting multiple threads for your application, just add the --enable-threads option. But I don't understand what it means by threads support without starting multiple threads. If I don't want to start multiple threads, why do I need to enable threads?

uwsgi \
  --uid uwsgi \
  --master \
  --plugins http,python3,stats_pusher_statsd \
  --http :8080 \
  --buffer-size 32768 \
  --enable-threads \
  --wsgi-file api/uwsgi.py


Solution

  • The meaning of this flag is to enable threads within your script while uWSGI threads is disabled. It is needed only if you implemented threads in your script but don't want uWSGI to start its own threads.

    Original description:

    If you start uWSGI without threads, the Python GIL will not be enabled, so threads generated by your application will never run.

    <...>

    If you want to maintain Python threads support without starting multiple threads for your application, just add the --enable-threads option (or enable-threads = true in ini style).