Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.