In the past I've gone the path Jervis has recommended. In my case, the issue was that PSSE would crash during the fault list or have a criteria violation.
Python was in control using the subprocess command to launch PSSE with an IDEV argument. It was kind of a hack-job but basically it would periodically check if the PSSE process was still running and also scan the log file for violation notifications. If violations were detected, then it would kill the process, make some modifications, and re-run it.
I guess the important question is - what is causing your simulations to hang? What is the best way to detect this condition?
Here's some code below that can be improved upon. The idev it's launching is "run_stab_wvoltage". I remember the first argument to Popen being somewhat sensitive to special characters.
import subprocess
try: #to open pss/e with the newly created idv.
pssdsInstance = subprocess.Popen(
["C:\\progra~1\\pti\\psse30\\pssbin\\PSSDS430.exe", '-buses','80000','-inpdev', 'run_stab_wvoltage.idv'],
cwd= activation_path + "\\" + case + "\\", #path where launching PSSE from
shell=False,
creationflags=512|16 #CREATE_NEW_PROCESS_GROUP|CREATE_NEW_TERMINAL
)
logging.info( "PSSE Successfully Launched! Running %s\%s\%s at %d MW" % (case, condition, faultName, faultMW))
except:
logging.warning( "ERROR WITH POPEN and PSS/E")
I then used the following commands to see/modify what the process was up to, although you could certainly do something fancier.
pssdsInstance.poll() #Still running?
pssdsInstance.terminate() #Kill the process
Good luck!
Sorry, I forgot to say that I am running dynamics. By "hung up" I mean that some error in the fault file has caused pss/e to pause and wait for some input, basically anything that would not return from the psspy.runrspnsfile command.
Example: for fault in os.listdir('faultfile'): psspy.runrspnsfile(...file path..) I'm just unsure if handling the exception with a try/except would handle this case since it is waiting on a return from another function.
So the problem lies in your response file? Those files can be waiting on user input, and 'hang' indefinitely