2

Python threads in PSSE

I tried to implement wxPython aplication with additional thread for calculations and update wxPython progress dialog within that thread. But psse crashes all the time.

So after that i tried to run really simple multithread python script in psse and it also caused psse crash. There is simple multithread psse script

import threading
import time

class TestThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        for i in range(0, 60, 3):
            print "T2: ", i
            time.sleep(3)

TestThread().start()
for i in range(0, 60, 2):
    print "T1: ", i
    time.sleep(1)

So my question is does psse allow to use threads in python script?

zeeegis's avatar
45
zeeegis
asked 2012-12-10 05:08:10 -0500, updated 2012-12-10 05:09:49 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

3 Answers

2

I followed your advice. Starting the thread also caused my PSSE instance to hang. There wasn't any error message, but the program never finished.

I changed the program so that there were no sleep statements at all, so it should have finished very quickly, but still PSSE wasn't able to run the program to completion. It just becomes non-responsive.

It may be that you are unable to run threads from inside of the PSSE program. Here is how to run a loadflow inside a thread, from outside of PSSE.

import sys
import os
import threading
import time


PSSE_LOCATION = r'c:/program files/pti/psse32/pssbin'
sys.path.append(PSSE_LOCATION)
os.environ['PATH'] += ';' + PSSE_LOCATION

import psspy
psspy.throwPsseExceptions = True

class RunLoadflow(threading.Thread):
    def __init__(self, savefilename):
        super(RunLoadflow, self).__init__()
        self.casename = savefilename

    def run(self):
        psspy.case(self.casename)
        psspy.fnsl()

psspy.psseinit(8000)
CASENAME = r"c:/program files/pti/psse32/example/savnw.sav"
thread = RunLoadflow(CASENAME)
thread.start()
thread.join()

This might help you restructure your Python code so that it runs outside of the PSSE program.

JervisW's avatar
1.3k
JervisW
answered 2012-12-11 00:39:05 -0500
edit flag offensive 0 remove flag delete link

Comments

This looks right to me. I am attempting to do a similar thing. For some reason the sleep function causes the thread to hand in PSSE, even from the command line.

KyleA's avatar KyleA (2013-06-21 15:15:55 -0500) edit

An additional question, have you tried running multiple threads in parallel? I get some strange results with cases apparently crossing up each other. Is there a known way to force PSSE to keep itself separate when initialized multiple times?

KyleA's avatar KyleA (2013-06-21 15:16:53 -0500) edit
add a comment see more comments
0

Check this one...python thread basics

walshmagger's avatar
1
walshmagger
answered 2017-10-05 23:56:29 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
-1

Can someone please tell me about the basics of Python Programming ??? I mean where should i write my program how to link it with PSSE and how to get it simulated . PLEASE!

The Bull's avatar
1
The Bull
answered 2012-12-24 00:57:03 -0500
edit flag offensive 0 remove flag delete link

Comments

Here's a tutorial page for PSSE + Python http://www.whit.com.au/blog/python-for-psse-tutorial/ that we wrote. I'm adding stuff all the time, so let me know if you think of other topics to put on i!!

JervisW's avatar JervisW (2012-12-24 03:18:10 -0500) edit
add a comment see more comments

Your Answer

Login/Signup to Answer