2

I have a python script that run for few hours to process each record. Also, at the same time, I want to run the same script but with other arguments for other purpose.

Sometime an exception is raised and cause the script stop. Sometime the OS got restart.

So I would like to have something at the OS level to check. Such that if the script is stop, restart the script.

What is the best approach to solve this problem?

user1187968
  • 7,154
  • 16
  • 81
  • 152
  • This isn't really Python-specific -- the best practice is to use whichever process supervision system is supported by your OS vendor, *no what language your software is written in*. – Charles Duffy Dec 23 '17 at 02:04
  • If your OS vendor supports Upstart? Use Upstart. They support systemd? Use systemd. They support launchd? Use that. They don't ship anything at all? Think about [Runit](http://smarden.org/runit/) or [Daemontools](https://cr.yp.to/daemontools.html) or [Supervisor](http://supervisord.org/introduction.html) or [s6](https://skarnet.org/software/s6/). (Personally, in such a situation, I'd lean towards s6 or runit). – Charles Duffy Dec 23 '17 at 02:07
  • ...the big reason this question is frowned on, by the way, is that in asking for "the best" X, when there are a whole lot of implementations of X around, it gets towards being an opinion poll or a recommendation request (see #2 in "some questions are still off-topic" at https://stackoverflow.com/help/on-topic) rather than something where a canonical, objectively complete and correct answer exists. – Charles Duffy Dec 23 '17 at 02:11

1 Answers1

3

I found myself asking a similar question not too long ago. I had used PM2 for NodeJS apps and found Supervisor to more general and very similar. Very clean web interface to monitor process statuses remotely and the events API is very helpful for automatic notifications if processes fail.

Skam
  • 7,298
  • 4
  • 22
  • 31
  • 2
    This is more of a comment than an answer. Or else it's a 'link only answer'. You should consider buffing the answer with more information – Alan Kavanagh Dec 23 '17 at 01:57
  • (Personally, I consider a web interface a liability rather than a feature -- that's attack surface, as opposed to a standard control socket -- as used by the majority of other supervision systems -- where UNIX permissions allow granular control over which accounts can/can't open for write). – Charles Duffy Dec 23 '17 at 02:14