1

Capture keyboard interrupt in PSS/E script?

Hi, I'm wondering if it's possible to capture a keyboard interrupt while running a python script in PSS/E. I need to run long scripts that could take upwards of half an hour, so if I see something wrong, I want to be able to halt the execution. Any ideas?

Thanks, Kyle

KyleA's avatar
87
KyleA
asked 2013-04-08 09:58:19 -0500, updated 2013-04-09 13:58:07 -0500
edit flag offensive 0 remove flag close merge delete

Comments

2

Thanks for the help Eli and Jervis. I suspected as much but I'm hardly an expert. I have run my scripts using python to initialize PSS/E before so maybe that's the way to go.

KyleA's avatar KyleA (2013-04-09 13:53:23 -0500) edit
add a comment see more comments

1 Answer

1

F10 is the only interrupt command that I'm aware of. It will pause your script, but then there's no good way to get back into PSSE without resuming it or killing the process. If that doesn't satisfy you, I'd suggest running your script from outside PSSE and opening PSSE from your script. I run most of mine from Sublime Text 2, and I can interrupt them at any time.

(edit) Here is how you could check if a key has been pressed if you ran you Python scripts outside of PSSE:

import time
import msvcrt

while 1:
    print "Doing some hard work (q to quit)"
    time.sleep(2)

    if msvcrt.kbhit():
        key = msvcrt.getch()

        # exit if the user presses "q"
        if key.lower() == 'q':
            break
        else:
            print "%s key pressed" % key

It's using the msvcrt module which comes with Python on Windows. The output would look something like this

Doing some hard work (q to quit)
Doing some hard work (q to quit)
w key pressed
Doing some hard work (q to quit)

For someone that typed w and then later the q key to quit. Here are the official docs for that module: http://docs.python.org/2/library/msvcrt.html#console-i-o

I'm using kbhit to check if a key was pressed. Then getch to get the key and comparing it to q.

Eli Pack's avatar
823
Eli Pack
answered 2013-04-08 18:26:51 -0500
JervisW's avatar
1.3k
JervisW
updated 2013-04-08 22:38:17 -0500
edit flag offensive 0 remove flag delete link

Comments

Eli is correct. When PSSE is running your Python script. It hides it deep within it's bowels somewhere. It doesn't receive any keyboard or mouse events. You can't interact with the PSSE UI either. And halting the script and re-entering is impossible too.

JervisW's avatar JervisW (2013-04-08 22:30:58 -0500) edit

I just tried F10, and even that doesn't work.

JervisW's avatar JervisW (2013-04-08 22:33:06 -0500) edit
add a comment see more comments

Your Answer

Login/Signup to Answer