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

Ask Your Question
0

How to terminate python script without closing PSSE?

asked Apr 4 '5

trc gravatar image

stop2 and pssehalt2 both close everything. Just need to catch errors and return values without crashing the whole application.

2 answers

Sort by » oldest newest most voted
0

answered Apr 8 '5

jconto gravatar image

updated Apr 8 '5

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
link

Comments

Nice way to do it

likethevegetable gravatar imagelikethevegetable (10 hours ago)
0

answered Apr 7 '5

likethevegetable gravatar image

updated Apr 7 '5

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.

link

Comments

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.

trc gravatar imagetrc (Apr 7 '5)

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

likethevegetable gravatar imagelikethevegetable (Apr 7 '5)

I see, thanks.

trc gravatar imagetrc (Apr 7 '5)

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

1 follower

Stats

Asked: Apr 4 '5

Seen: 38 times

Last updated: 2 days ago