Python watchdog for another Python process technique?

 ̄綄美尐妖づ 提交于 2019-12-06 14:43:44

问题


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

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()

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?

Best


回答1:


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.



来源:https://stackoverflow.com/questions/10922754/python-watchdog-for-another-python-process-technique

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!