skip to Main Content

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


  1. To close the script definitely, use:

    import sys
    
    ...
    
    sys.exit()
    

    EDIT: It seems the Photoshop process is still opened. Before exiting, try:

    proc.terminate()
    

    but I don’t have Photoshop to test.

    Login or Signup to reply.
  2. You can use exit() or sys.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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search