python - 在 Python-RQ 中减少机器上的 worker 数量?

标签 python redis python-rq

在 Python-RQ 中减少机器上工作人员数量的好方法是什么?

According to the documentation ,我需要向机器上的工作进程之一发送 SIGINT 或 SIGTERM 命令:

Taking down workers

If, at any time, the worker receives SIGINT (via Ctrl+C) or SIGTERM (via kill), 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 or SIGTERM is received again,the worker will forcefully terminate the child process (sending it SIGKILL), but will still try to register its own death.

这似乎意味着大量的编码开销:

  • 需要跟踪工作进程的 PID
  • 需要有一种方法从远程机器发送 SIGINT 命令

我真的需要自定义构建它吗,或者有没有一种方法可以使用 Python-RQ 库或其他一些现有库轻松地做到这一点?

最佳答案

  1. 使用rq.Worker.all()获取所有正在运行的worker
  2. 选择你想杀死的 worker
  3. 使用os.kill(worker.pid, signal.SIGINT)

关于python - 在 Python-RQ 中减少机器上的 worker 数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15125464/

相关文章:

python - Youtube-dl 在 python-rq 任务中监控状态

python - 将相同的连续值分组到 pandas 中并存储 : values, 索引和列切片

python - 属性错误 : 'Series' object has no attribute 'searchsorted' pandas

python - 解释深度神经网络的训练轨迹 : very low training loss and even lower validation loss

python - lxml - 如何优雅地标记文本中的单词?

php - Symfony 使用 Redis 作为默认缓存编译容器

Redis 服务失败,附加文件权限被拒绝

java - Jedis 永远阻止与亚马逊的连接

redis - 使用 python-rq (redis) 在多个服务器上进行远程工作

python - Flask session UnpickleError