Ask Your Question
1

How to terminate python script without closing PSSE?

asked 2025-04-04 15:33:02 -0500

trc gravatar image

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

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2025-04-07 13:08:32 -0500

likethevegetable gravatar image

updated 2025-04-07 14:16:49 -0500

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.

edit flag offensive delete link more

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 ( 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 gravatar imagelikethevegetable ( 2025-04-07 14:13:00 -0500 )edit

I see, thanks.

trc gravatar imagetrc ( 2025-04-07 14:18:57 -0500 )edit
0

answered 2025-04-07 20:14:00 -0500

jconto gravatar image

updated 2025-04-07 20:24:07 -0500

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
edit flag offensive delete link more

Comments

Nice way to do it

likethevegetable gravatar imagelikethevegetable ( 2025-04-09 10:13:10 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: 2025-04-04 15:33:02 -0500

Seen: 73 times

Last updated: Apr 07