在 Python-RQ 中减少机器上工作人员数量的好方法是什么?
According to the documentation ,我需要向机器上的工作进程之一发送 SIGINT 或 SIGTERM 命令:
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.
这似乎意味着大量的编码开销:
- 需要跟踪工作进程的 PID
- 需要有一种方法从远程机器发送 SIGINT 命令
我真的需要自定义构建它吗,或者有没有一种方法可以使用 Python-RQ 库或其他一些现有库轻松地做到这一点?
最佳答案
- 使用
rq.Worker.all()
获取所有正在运行的worker - 选择你想杀死的 worker
- 使用
os.kill(worker.pid, signal.SIGINT)
关于python - 在 Python-RQ 中减少机器上的 worker 数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15125464/