简体   繁体   English

完成后如何自动重新运行python程序? Supervisord?

[英]How to automatically rerun a python program after it finishes? Supervisord?

I have a python program that I would like to constantly be running updates and gathering new data. 我有一个Python程序,我想不断运行更新并收集新数据。 Essentially, I am gathering data from a bunch of domains. 本质上,我从许多域中收集数据。 My processors take about a day and a half to run. 我的处理器大约需要一天半的时间才能运行。 Once they finish, I'd like them to automatically start over again. 一旦完成,我希望他们自动重新开始。

I don't want to use a while loop to just restart the processes without killing everything related first because some of the packages that I am using to support these processors (mainly pyV8) have a problem of memory slowly accumulating and I'm not a good enough programmer to dive into debugging a memory leak in a big package like that. 我不想使用while循环来重新启动进程而不先杀死所有相关的东西,因为我用来支持这些处理器的某些软件包(主要是pyV8)存在内存缓慢累积的问题,而我不是足够好的程序员可以像这样在大型程序包中调试内存泄漏。 So, I need all of the related processes to successfully die and then come back to life. 因此,我需要所有相关过程来成功消亡,然后重获新生。

I have heard that supervisord can do this type of work, but don't like messing around with .conf files and would prefer to keep everything inside of python. 我听说supervisord可以完成这类工作,但不喜欢把.conf文件弄乱,而宁愿将所有内容都保留在python中。

Summary: Is there a package that will kill all related processes with a script/package that I could use to put into a while loop or create this kind of behavior inside of a python script? 简介:是否有一个软件包可以杀死某个脚本/软件包的所有相关进程,而我可以使用它们将该脚本/软件包放入while循环或在python脚本内部创建这种行为?

I don't see why you couldn't use supervisord . 我不明白为什么您不能使用supervisord The configuration is really simple and very flexible and it's not limited to python programs. 该配置非常简单且非常灵活,并且不仅限于python程序。

For example, you can create file /etc/supervisor/conf.d/myprog.conf : 例如,您可以创建文件/etc/supervisor/conf.d/myprog.conf

[program:myprog]
command=/opt/myprog/bin/myprog --opt1 --opt2
directory=/opt/myprog
user=myuser

Then reload supervisor's config: 然后重新加载主管的配置:

$ sudo supervisorctl reload

and it's on. 它在。 Isn't it simple enough? 这还不够简单吗?

More about supervisord configuration: http://supervisord.org/subprocess.html 有关supervisord配置的更多信息: http : //supervisord.org/subprocess.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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