我有几个python脚本。在第一个脚本中,当满足某些条件时,第二个脚本将启动:
count += 1
if count == 3:
fin = Popen("python3 autoclear.py", shell=True)如何才能在根据条件启动新脚本时,原脚本停止工作?
我之前找到的解决方案完全中断了python (完成解释器),而不是特定的脚本。
发布于 2020-02-23 00:04:13
为什么需要启动一个新的Python解释器?
您可以将这两个脚本放在一个包中,将autoclear中完成的操作放在一个函数中,并在主文件中调用此函数。
结构
current_folder
script.py
/script_package
__init__.py
autoclear.py在autoclear.py中
def autoclear():
# put everything in this function在script.py中
from script_package.autoclear import autolclear
count += 1
if count == 3:
fin = autoclear()编辑
回答这条评论,如果你真的需要这样做,我认为在后台调用Python进程应该是可行的:
count += 1
if count == 3:
fin = Popen("python3 autoclear.py &", shell=True)Edit2:你可以尝试使用ansible,这个answer可能会有帮助。
https://stackoverflow.com/questions/60352798
复制相似问题