简体   繁体   中英

Python watchdog for another Python process technique?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM