Ask Your Question
1

Python crashes when trying open a second case file

asked 2012-11-10 09:07:35 -0600

Forgotten gravatar image

updated 2012-11-10 09:38:59 -0600

I am using Python 2.7 to make API calls fir PSSE 30. My code works for a single run but crashes if I try to do multiple. There are definitely some variables I need to reset before I can do another run but I'm not sure what they are.

I defined the following commands in function and return their error codes. The main body loops the function through multiple cases. First run works fine, if the dynamic case can't run it tells me through the codes. Even if it can though the second run crashed and Windows pops up with a message that python has stopped working.

psspy.psseinit(150000)
psspy.case(caseFile)
psspy.runrspnsfile(convertIdv)
psspy.dyre_new([1,1,1,1],dynDate,"1","1","1")
psspy.strt(1,"")
psspy.run(1,1,60,1,5)
psspy.pssehalt_2()

How do I reset the PSSE API/clear only the variables from the function I've defined without wiping the error list I'm returning?

EDIT: By removing pssy.pssehalt_2() I can get it to run four cases before it crashes. I do not understand why though.

edit retag flag offensive close merge delete

Comments

@Raithyn Also I just noticed, are you really using Python 2.7 with PSSEv30? I thought PSSEv30 used an earlier version of Python like Python 2.3 or Python 2.4

JervisW gravatar imageJervisW ( 2012-11-11 03:55:13 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2012-11-11 03:53:46 -0600

JervisW gravatar image

Hi,

To answer this I might need to make some guesses at how your program was written. Let me know if I've guessed incorrectly anywhere:

import psspy

def run_dynamic_study(caseFile, convertldv, dynDate):
    psspy.psseinit(150000)
    psspy.case(caseFile)
    psspy.runrspnsfile(convertIdv)
    psspy.dyre_new([1,1,1,1],dynDate,"1","1","1")
    psspy.strt(1,"")
    ierr = psspy.run(1,1,60,1,5)
    psspy.pssehalt_2()
    return ierr

dynamic_info = [("casefile1.sav", "dynamics.idv", "dynamics-10-10-2012.dyr"),
                ("casefile2.sav", "dynamics.idv", "dynamics-11-10-2012.dyr")]

for caseFile, convertIdv, dynDate in dynamic_info:
    ierr = run_dynamic_study(caseFile, convertIdv, dynDate)
    if ierr: 
        print "Got ierr=%d" % ierr
        break

I'm not entirely sure what the problem with your script is just yet - there is too little information. It sounds like Python enters an endless loop somewhere and you get a message like "Python has stopped responding".

You might be using a while loop instead of my for loop, and your program never exits the while loop.

There may also be an error from any one of those psspy function calls. Here is a method for finding where your program has an error quickly:

import psspy
psspy.throwPsseExceptions = True

Write that second line: psspy.throwPsseExceptions = True. It will stop (crash) your program and show you exactly where one of your psspy function calls has an error, now you don't have to play a guessing game, or pass ierr codes around your program.

Update your question once you've had a chance to try out some of these ideas

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

Stats

Asked: 2012-11-10 09:07:35 -0600

Seen: 2,807 times

Last updated: Nov 11 '12