2

I have a python file, foo.py. It downloads some google sheets data with gspread, process it, and reuploads. It takes typically 15-25 seconds on my dataset. Sometimes, about 20%, it'll run indefinitely, or at least as long as I've had patience to wait for.

I want to run it on a schedule, as often as is possible. But I find that something like using watch doesn't keep running it after the first freeze up.

Thoughts?

David Lerner
  • 344
  • 3
  • 14
  • The [crontab](http://kvz.io/blog/2007/07/29/schedule-tasks-on-linux-using-crontab/) is your friend. – jedwards Mar 07 '15 at 02:01

1 Answers1

2

You need a monitor (AKA watchdog) parent-process, which spawns the child process you're actually interested in running, waits a couple minutes, then kills the child if it's not terminated yet (then it might just exit and wait for the next reschedule, or try a few times to schedule the child process again).

Use your favorite scheduling mechanism to schedule the parent (monitor/watchdog) process, and you'll be all set.

This is a sound architecture pretty much independently of the programming language involved in the child (actual target) and parent (monitor) processes. For hints on a Python implementation of the monitor parent process, see e.g Using module 'subprocess' with timeout ...

Community
  • 1
  • 1
Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395