First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

Ask Your Question
0

Activate PSSE License from Python

asked Sep 18 '12

JervisW gravatar image

Is it possible to control the activation of the PSSE license from within Python?

I'm running a program that doesn't need to use PSSE much, and it seems like a waste to use the hourly license up for the time that PSSE isn't required.

1 answer

Sort by » oldest newest most voted
1

answered Sep 19 '12

jsexauer gravatar image

updated Sep 28 '12

JervisW gravatar image

I think putting code which requires PSSE in its own thread would do the trick. I can't verify the license is not checked out (I'm not sure how to do that), but I'm pretty sure this works:

import sys, os
import threading

class ThreadClass(threading.Thread):
    def __init__(self, caseFilename):
        threading.Thread.__init__(self)
        self.caseFilename = caseFilename

    def run(self):
        # Import psspy and do your code requiring psse here.
        print 'Executing code which DOES require PSSE...'

        PSSE_LOCATION = r"C:\Program Files\PTI\PSSE32\PSSBIN"
        sys.path.append(PSSE_LOCATION)
        os.environ['PATH'] = os.environ['PATH'] + ';' +  PSSE_LOCATION
        import psspy

        psspy.psseinit(100000)
        psspy.case(self.caseFilename)

def main():
    # Do non-PSSE tasks
    print 'Executing code which DOES NOT require PSSE...'
    caseFilename = r'C:\path\to\case\case.sav'


    # Do PSSE tasks
    t = ThreadClass(caseFilename)
    t.start()
    t.join()    # Wait for PSSE process to finish (comment out to run in parallel)

    # Do more non-PSSE tasks
    print 'Test to see if PSSE is avaliable...'
    try:
        print psspy.psseversion()
    except NameError:
        print 'Success!  psspy is not imported, so license should not be checked out'

if __name__ == '__main__':
    main()

(edit - JervisW)

Here is the code that I used to verify that the PSSE license once activated in the thread will continue in the main program.

import threading

def initpsse():
  import psspy
  import os
  import sys

  PSSE_LOCATION = r"C:\Program Files\PTI\PSSE32\PSSBIN"
  sys.path.append(PSSE_LOCATION)
  os.environ['PATH'] = os.environ['PATH'] + ';' +  PSSE_LOCATION
  psspy.psseinit(10000)
  psspy.case('base.sav')

psse_background_thread = threading.Thread(target=initpsse)
psse_background_thread.start()
psse_background_thread.join()

# now to check if the case isn't correctly loaded.
import psspy
psspy.throwPsseExceptions = True

try:
  psspy.case('base.sav')
except psspy.CaseError:
  print "Success! PSSE isn't initialised"
else:
  print "Failure! PSSE is still initialised in the main program"
link

Comments

I should be able to test this out. I'll let you know how it goes. An interesting experiment.

JervisW gravatar imageJervisW (Sep 20 '12)

I'm excited to see if it works.

jsexauer gravatar imagejsexauer (Sep 20 '12)

unfortunately it doesn't work. That `NameError` is due to the fact that you haven't imported `psspy` in the global scope, rather than psspy not being initialised in the main thread. Behind the scenes, psse is globally initialised and closing the thread does not close the license.

JervisW gravatar imageJervisW (Sep 28 '12)

Perhaps the one way is to run PSSE in a completely separate subprocess and then communicate with the main program somehow through messages. If I get something up and running I'll post a 'how-to'

JervisW gravatar imageJervisW (Sep 28 '12)

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

Stats

Asked: Sep 18 '12

Seen: 2,225 times

Last updated: Sep 28 '12