Forum: Poser Python Scripting


Subject: Anyone with Python RPC/IPC experience?

an0malaus opened this issue on Aug 30, 2019 ยท 7 posts


ironsoul posted Sat, 31 August 2019 at 6:56 AM

Yes, would be good if Poser python could support pip :)

Regarding launching an external script this can be done with the subprocess.popen function. The code I tested is Windows, I'm assuming popen also works in Mac/Unix land.

The following would be in the Poser python code...

import subprocess
import os
poserpid = os.getpid()
subprocess.Popen(["cmd.exe","/c python c:/tmp/checklock.py "+ poserpid.str()],creationflags=subprocess.CREATE_NEW_PROCESS_GROUP)

The external python script could then grab the poserpid as a process arg and go into a check,sleep loop waiting for Poser to finish before carrying out any tidy up actions.

Checkng for process pids is os specific. There is a stackoverflow article here

Other approaches are to use a global resource like semaphore locks or file locks to keep the two programs aware of each other. The main thing is to chose a method that auto clears up on Poser exit irrespective of how it terminated...