How to terminate python script without closing PSSE?
stop2 and pssehalt2 both close everything. Just need to catch errors and return values without crashing the whole application.
First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!
stop2 and pssehalt2 both close everything. Just need to catch errors and return values without crashing the whole application.
You can put the code within a "1-loop" for-loop and break out of it at different 'stages' (effectively jumping to the end and not using quit() or sys.exit()):
# long code
for i in range(1):
do something
if error1: break
do also...
if error2: break
...
and so on
# end of long code
Nice way to do it
Are you running PSSE from within Python, or running a Python script in the GUI? You can try exit(), or put your Python code in a function and use return.
def my_stuff():
some code
if stop_script:
return
some other code
my_stuff()
You can also wrap your function in a try-except clause if you want to terminate it if there's a failure.
Python in the GUI. exit()/quit() do the same - just close the whole instance. It sounds like the only way to do this is have something that jumps to the end of the script? Very inconvenient/dirty since I'll have to constantly check for some kind of "quit" flag at any relevant stage.
It's not that inconvenient or dirty. Put your contents in a function (it's a good practice anyways). When you want to stop running, use a return statement. Easy peasy. See the edit. You'd have to check for some quit flag/condition at any stage regardless. You could also put it in a try except clause
I see, thanks.
Asked: Apr 4 '5
Seen: 38 times
Last updated: 2 days ago