I’m using a script that checks if the wine process is properly launched. If not, stop the wine process and relaunch it till the program properly boots.
My problem is when I quit the program after using it, My python script is still running in the terminal, and doesn’t exit.
Can somebody help me to properly exit the script when I close 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())
2
Answers
To close the script definitely, use:
EDIT: It seems the Photoshop process is still opened. Before exiting, try:
but I don’t have Photoshop to test.
You can use
exit()
orsys.exit([reason])
if you want to use the sys.exit function, you have to import sys first.If you only want to close the While loop, use break.