1

How to terminate python script without closing PSSE?

  • retag add tags

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

trc's avatar
9
trc
asked 2025-04-04 15:33:02 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

1

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.

likethevegetable's avatar
101
likethevegetable
answered 2025-04-07 13:08:32 -0500, updated 2025-04-07 14:16:49 -0500
edit flag offensive 0 remove flag delete 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's avatar trc (2025-04-07 13:24:12 -0500) edit

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's avatar likethevegetable (2025-04-07 14:13:00 -0500) edit

I see, thanks.

trc's avatar trc (2025-04-07 14:18:57 -0500) edit
add a comment see more comments
0

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
jconto's avatar
2.9k
jconto
answered 2025-04-07 20:14:00 -0500, updated 2025-04-07 20:24:07 -0500
edit flag offensive 0 remove flag delete link

Comments

Nice way to do it

likethevegetable's avatar likethevegetable (2025-04-09 10:13:10 -0500) edit
add a comment see more comments

Your Answer

Login/Signup to Answer