Web app, spawn spawner, thread - redis queue vs spwn thread directly
My employee wrote this
class Worker(object):
WORKER_LIMIT = 2
queue = Queue()
@classmethod
def enqueue(cls, _type, args):
cls.queue.put((_type, args))
@classmethod
def handle_event(cls, event):
pass
@classmethod
def worker(cls):
while True:
event = cls.queue.get(True)
cls.handle_event(event)
cls.queue.task_done()
@classmethod
def start(cls):
for i in range(cls.WORKER_LIMIT):
w = Thread(target=cls.worker)
w.daemon = True
w.start()
worker = Worker()
worker.start()
It uses this to call a background process to do a heavy task (which is great). But I have a bad felling about it. Is it a lot of zombies? Our application server works with nginx and gunicorn.
I myself will use some redis task queue to send a job to an external worker. I don't like the idea of ββcreating a thread directly from a web app. Do you have any ideas?
+3
source to share
No one has answered this question yet
Check out similar questions: