A friend of mine wrote to me a Python script that launch Photoshop with wine, using subprocess.Popen
.
#!/usr/bin/env python3
import subprocess, re, sys, signal
error_keywords = re.compile('^.*(Assertion|0x65372a0).*$')
success_keywords = re.compile('^.*(list_manager_QueryInterface).*$')
exited = False
process = None
successful_launch = False
timeout = 3
def kill_photoshop(signalnum, frame):
if not successful_launch:
print("No successful launch withing %d seconds, killing photoshop ..."%timeout, file=sys.stderr)
process.kill()
signal.signal(signal.SIGALRM, kill_photoshop)
while not exited:
process = subprocess.Popen(["wine64", "/home/artik/.wine/drive_c/Program Files/Adobe/Adobe Photoshop CC 2019/Photoshop.exe"], stderr=subprocess.PIPE)
successful_launch = False
signal.alarm(timeout)
while True:
if process.poll():
break
line = process.stderr.readline()
# print("got line %d and process %s"%(len(line),process.poll()))
if len(line) == 0 and process.poll() is not None:
if process.poll() == 0:
exited = True
break
if line:
print(line.strip())
if success_keywords.match(str(line)):
print("Successful photoshop launch detected", file=sys.stderr)
successful_launch = True
if error_keywords.match(str(line)):
print("Error keyword match, killing process", file=sys.stderr)
process.kill()
break
print("Process return code %d"%process.wait())
Since few days a bug is fixed, adding a setting to the wine launch command. The old line:
wine64 "/home/artik/.wine/drive_c/Program Files/Adobe/Adobe Photoshop CC 2019/Photoshop.exe"
And the new one:
__GL_MaxFramesAllowed="1" wine64 "/home/artik/.wine/drive_c/Program Files/Adobe/Adobe Photoshop CC 2019/Photoshop.exe"
So I have to add __GL_MaxFramesAllowed="1"
to my process. I tried adding a variable in the script:
my_env = __GL_MaxFramesAllowed="1"
I tried
process = subprocess.Popen(["wine64", "/home/artik/.wine/drive_c/Program Files/Adobe/Adobe Photoshop CC 2019/Photoshop.exe"], env=my_env, stderr=subprocess.PIPE)
But doesn’t work. How to fix it ?
3
Answers
Are you able to launch from the CLI using the same command manually? If not, I would suggest getting that working first, then convert that into Python.
The
env
parameter toPopen
must be a mapping (i.e. a dict).In addition, you’ll probably want to copy your current environ and add to it:
another option would be to exec the
env
program, i.e. your launch line would be:but doing it natively in Python is probably better!