Ask Your Question
2

Problems stopping or halting PSSE in a Python script

asked 2012-11-15 14:25:13 -0500

AdamF gravatar image

I am having some issues stopping or halting PSSE.

When I use psspy.stop_2(), PSSE stops successfully but my python code also stops executing and the interpreter closes, preventing the rest of my program from running. Why does stop_2 have the power to crash the python interpreter?

When I use psspy.halt_2(), one of the following happens, depending somehow on whether the PSSE GUI has been running or IDLE has been re-started since the last attempt.
1) PSSE halts successfully allowing my code to continue executing, but the usual message box telling me how many hours are left on my hourly dongle appears and pauses the execution of pyton code until dismissed manually. The message box can be somewhat annoying and reduces the effectiveness of my program.
2) PSSE crashes and displays a message box: "Failure of license thread! Please shutdown this program within 1 minute and then notify PTI." Sometimes Python continues executing my code after this and sometimes Python crashes too before finishing my program.

I have also noticed that sometimes, even though there is no visible evidence of PSSE or python running, my hours get used up after running a python script. This is one reason that I would like to reliably stop PSSE in my scripts. The other reason is that I would like to be able to compile a DLL and then restart PSSE in order to load the new DLL, all within the same script.

I am using PSSE V32.1.2 - hourly dongle license, Python 2.5.1, Windows 7.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2012-11-15 16:22:57 -0500

JervisW gravatar image

Hi Adam, Here are some quick answers - I'll follow them up with a more detailed look at how it works.

Why does stop_2 have the power to crash the python interpreter?

The PSSE code calls into a compiled dll function. Compiled functions (often written in C) execute outside the control of the Python interpreter. When the dll function crashes or exits it crashes Python too - So you can't catch the exception.

[...] my hours get used up after running a python script

This may be due to IDLE. It isn't a particularly well written editor. What happens is that even though you've finished running your script, the Python session can live on in the background and can chew up your hours (because PSSE is still initialised). For this reason I've stopped using IDLE, and begun using Sublime Text - though there are plenty of free text editors available that are quite good at what they do.

Here is how I figured out what stop_2 is doing in the background:

import psspy
import dis

dis.dis(psspy.stop_2)

This disassembles the function into Python bytecode. With enough practice you can learn to read Python bytecode and turn its output from this:

14884    0 LOAD_GLOBAL    0 (psspyc)
         3 LOAD_ATTR      1 (stop_2)
         6 CALL_FUNCTION  0
         9 STORE_FAST     0 (retval)

into this

def stop_2():
    retval = psspyc.stop_2()

Where psspyc is their compiled dll file PSSBIN\psspyc.pyd.

This topic raises another question: How do you all minimise your hourly usage? I might ask that separately.

edit flag offensive delete link more

Comments

Thanks for the information, very interesting. I'll have to try another editor at some point but I'm a bit concerned about maintaining compatibility with other PSSE/python users who are using IDLE. Any info regarding psspy.pssehalt_2()?

AdamF gravatar imageAdamF ( 2012-11-20 15:54:02 -0500 )edit

Hi Adam, are you able to expand on that concern about maintaining compatibility with other users? I might be understanding you incorrectly, but you can use any text editor and still maintain compatibility (so long as you don't mix tabs and spaces www.python.org/dev/peps/pep-0008/)

JervisW gravatar imageJervisW ( 2012-11-20 17:29:24 -0500 )edit

I haven't used `pssehalt_2` before. Do you think that it might close the connection to PSSE?

JervisW gravatar imageJervisW ( 2012-11-20 17:32:33 -0500 )edit

pssehalt_2 seems to stop PSSE from using hours and clears out PSSE's working memory. I haven't tested whether it will load a different DLL after 'halting'. The problem is that after 'halting' PSSE and then trying to 'init' PSSE again, it often crashes both PSSE and python.

AdamF gravatar imageAdamF ( 2012-12-14 14:41:41 -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

Stats

Asked: 2012-11-15 14:25:13 -0500

Seen: 2,977 times

Last updated: Nov 15 '12