Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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...' baseDir = r"F:\For Jon Kern\High Voltage" + '\' caseFilename = baseDir + r'06-03-2012\06032012-highvoltage-archivesolved.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()

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

threading class ThreadClass(threading.Thread): def init(self, __init__(self, caseFilename): threading.Thread.init(self) threading.Thread.__init__(self) self.caseFilename = 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...' baseDir = r"F:\For Jon Kern\High Voltage" + '\' '\\' caseFilename = baseDir + r'06-03-2012\06032012-highvoltage-archivesolved.sav'

r'06-03-2012\06_03_2012-high_voltage-archive_solved.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()

if name == 'main': main()

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...'
    baseDir = r"F:\For Jon Kern\High Voltage" + '\\'
    caseFilename = baseDir + r'06-03-2012\06_03_2012-high_voltage-archive_solved.sav'
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()
click to hide/show revision 4
Added test case showing the behaviour when using threading module.

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"