正确退出python 3脚本

时间:2019-05-21 13:09:38

标签: python-3.x

我正在使用一个脚本检查葡萄酒过程是否正确启动。如果没有,请停止酒过程并重新启动它,直到程序正确启动。

我的问题是使用完我的程序后,我的python脚本仍在终端中运行,并且没有退出。

关闭photoshop.exe时有人可以帮助我正确退出脚本吗?

#!/usr/bin/env python3

import subprocess, re

keywords = re.compile('^.*Assertion.*$')

while True:
    process = subprocess.Popen(["wine64", "/home/artik/.wine/drive_c/Program Files/Adobe/Adobe Photoshop CC 2019/Photoshop.exe"], stderr=subprocess.PIPE)
    while True:
        if process.poll():
            break
        line = process.stderr.readline()
        if line == '' and process.poll() is not None:
            break
        if line:
            print(line.strip())
            if keywords.match(str(line)):
                print("Error keyword match, killing process")
                process.kill()
                break
    print("Process return code %d"%process.wait())

1 个答案:

答案 0 :(得分:0)

要完全关闭脚本,请使用:

import sys

...

sys.exit()

编辑:看来Photoshop进程仍处于打开状态。退出之前,请尝试:

proc.terminate()

但是我没有要测试的Photoshop。