What is a good way to Reduce the number of workers on a machine in Python-RQ?
According to the documentation, I need to send a SIGINT or SIGTERM command to one of the worker processes on the machine:
Taking down workers
If, at any time, the worker receives
SIGINT
(via Ctrl+C) orSIGTERM
(viakill
), the worker wait until the currently running task is finished, stop the work loop and gracefully register its own death.If, during this takedown phase,
SIGINT
orSIGTERM
is received again,the worker will forcefully terminate the child process (sending itSIGKILL
), but will still try to register its own death.
This seems to imply a lot of coding overhead:
Do I really need to custom build this, or is there a way to do this easily using the Python-RQ library or some other existing library?
rq.Worker.all()
os.kill(worker.pid, signal.SIGINT)