| Server IP : 85.214.239.14 / Your IP : 216.73.216.27 Web Server : Apache/2.4.65 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 8.2.29 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/2/root/proc/self/root/usr/share/doc/uwsgi-core/examples/wsgi/ |
Upload File : |
from threading import Thread
import uwsgi
from six.moves import queue
CONSUMERS = 4
def consumer(q):
while True:
item = q.get()
print(item)
#... DO A HEAVY TASK HERE ...
q.task_done()
def spawn_consumers():
global q
q = queue.Queue()
for i in range(CONSUMERS):
t = Thread(target=consumer,args=(q,))
t.daemon = True
t.start()
print("consumer %d on worker %d started" % (i, uwsgi.worker_id()))
uwsgi.post_fork_hook = spawn_consumers
def application(env, start_response):
global q
# we pass a copy of the env dictionary as it gets cleared after yield/return
q.put(env.copy())
start_response('200 OK', [('Content-Type', 'text/html')])
yield "Task enqueued"