Ask Your Question
1

Capture keyboard interrupt in PSS/E script?

asked 2013-04-08 09:58:19 -0600

KyleA gravatar image

updated 2013-04-09 13:58:07 -0600

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

edit retag flag offensive 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 gravatar imageKyleA ( 2013-04-09 13:53:23 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-04-08 18:26:51 -0600

Eli Pack gravatar image

updated 2013-04-08 22:38:17 -0600

JervisW gravatar image

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.

edit flag offensive delete link more

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 gravatar imageJervisW ( 2013-04-08 22:30:58 -0600 )edit

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

JervisW gravatar imageJervisW ( 2013-04-08 22:33:06 -0600 )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

Stats

Asked: 2013-04-08 09:58:19 -0600

Seen: 1,282 times

Last updated: Apr 09 '13