gpt4 book ai didi

python进程包装器

转载 作者:行者123 更新时间:2023-12-01 06:07:48 26 4
gpt4 key购买 nike

我需要用 python 编写一个进程包装器,它将启动应用程序并在失败时重新启动它。这将被记录到从命令行传入的指定日志位置。这可能吗?

最佳答案

>>> from subprocess import Popen
>>> def spawner(cmd_list):
... while True:
... print "Running proc..."
... mon_proc = Popen(cmd_list)
... print "Proc exit: %s" % mon_proc.wait()
...
>>> spawner(['/bin/sleep', '3'])
Running proc...
Proc exit: 0
Running proc...
Proc exit: 0
Running proc...
Proc exit: 0
Running proc...

关于python进程包装器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7273744/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com