Python看门狗是否提供另一种Python处理技术? [英] Python watchdog for another Python process technique?

查看:229
本文介绍了Python看门狗是否提供另一种Python处理技术?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个无限期运行的实时数据采集器,每隔几秒钟就会通过HTTP采集数据并将其放入MySQL数据库中.

I have a realtime data grabber that runs indefinitely, grabbing data over HTTP and putting it in a MySQL database every few seconds.

在我的程序中,我有一段时间的True循环,只要最后一次产生的时间大于X秒,就会产生工作程序(下载数据并保存数据的函数):

In my program, I have a while True loop that spawns workers (functions that download the data and save it) whenever the last spawned time is greater than X seconds:

while True:
    if _last_updated - datetime.now() > timedelta(seconds=5):
        green_pool.spawn_n(worker) # yes I'm using Eventlet!
        _last_updated = datetime.now()

确保此模块始终有效,永不冻结且永不停机的最佳方法是什么?我应该检查绿色游泳池的大小吗?我正在考虑使用Python编写看门狗,您是否建议这样做?如果是这样,我应该记住什么?

What would be the best way to ensure that this module always does work, never freezes and is never down? Should I be checking the green pool size? I was thinking about writing a watchdog for it in Python, would you recommend doing so? If so, what things should I keep in mind?

最佳

推荐答案

这可能有些矫kill过正,但我​​会考虑使用 supervisord .这是一个用于控制其他进程的进程(有点类似于init.d).它将允许您启动/停止/重新启动包含while True:循环的控制脚本.如果停止运行,它还将自动重新启动控制脚本.

It might be overkill, but I would look at using supervisord. It's a process for controlling other processes (somewhat like init.d). It will allow you to start/stop/restart your control script containing the while True: loop. It will also auto-restart the control script if it stops working.

正如您提到的,您应该在控制脚本中保留选项卡大小以及工作程序生成的成功/失败选项.但是要确保控制脚本始终运行,主管可以满足要求.

As you mention, you should keep tabs on the pool size and the success/failure of worker spawning within your control script. But to ensure that the control script is always running, supervisord fits the bill.

这篇关于Python看门狗是否提供另一种Python处理技术?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆