This is because, after importing the application, the plug-in master process is working:
spawned uWSGI master process (pid: 7167) spawned uWSGI worker 1 (pid: 7169, cores: 1) spawned uWSGI http 1 (pid: 7170)
So, your thread, which prints i , starts in the main process, and your requests are processed by the worker. The worker sees i equal to 1 during a fork. If you move sleep before increment i , the process processes fork before the first increment.
You should use something like uwsgidecorators.thread :
from time import sleep import threading import uwsgidecorators i = 0 @uwsgidecorators.postfork @uwsgidecorators.thread def daemon(): global i while True: i += 1 print(i) sleep(3) def application(environ, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [str(i).encode()]
Threads, except the main one, are not copied during the fork.
Or use:
[uwsgi] master = false
source share