Cron 终止 Python 脚本?
我有一个“长”Python 脚本,大约需要 45[分钟] 才能运行。我使用另一个(“调度程序”脚本)python 脚本来运行这个长脚本。当我使用终端运行“调度程序”脚本时,一切正常(意味着“长”脚本运行没有任何问题)。
我经历了一些挣扎,但最终成功添加了“调度程序”脚本以每分钟运行一次 cron。所以它现在“运行”其他脚本并且工作正常。
问题是:每当脚本(由“调度程序”“运行”)有一行内容为:
print "hello"
或任何“打印”语句时,cron 作业就会运行,但会在 20-30 秒后终止。当我删除任何“打印”语句时,cron 会正常运行作业并且不会终止。
我想解决这种情况,并让脚本继续运行,即使其中有一些“打印”语句。有什么提示如何做吗?
PS 在“调度程序”中,我用来
subprocess.Popen([sys.executable, command])
“运行”所有其他 python 脚本。
I have a 'long' python script that takes roughly 45[min] to run. I use another (a 'scheduler' script) python script to run this long script. When I run the 'scheduler' script using the terminal, everything works perfectly (meaning, the 'long' script runs without any issues).
I had some struggles, but eventually succeeded adding the 'scheduler' script to run through cron every minute. so it now 'runs' other script and works OK.
Here is the problem: whenever a script (that is being 'run' by the 'scheduler') has a line that says:
print "hello"
or any 'print' statement, the cron job runs, but terminates after 20-30 seconds. When I remove any 'print' statements, cron runs the jobs normally and does not terminate.
I'd like to fix this situation, and have the scripts continue to run even if they have some 'print' statements in them. any hints how to do it?
P.S. from within the 'scheduler', I use
subprocess.Popen([sys.executable, command])
to 'run' all other python scripts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有预感,这是由于 cron 处理标准输出的方式造成的。你如何重定向输出?
来自http://aplawrence.com/BDD/bbcronbasics.html:
I have a hunch that it's due to the way
cron
handles stdout. How are you redirecting output?From http://aplawrence.com/BDD/bbcronbasics.html: