First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

Ask Your Question
2

Python file crashes on the second time

asked Oct 15 '12

Pablo Nicolas gravatar image

updated Oct 15 '12

Hi all, I've done a python file with windows using wxpython library. If I run my python file from PyScripter I´ve no problems. When I run my python file from PSSE (Run Automation File button) I´ve no problems in the first time, but if I run this python file again, it crashes! Anyone knows this problem? I think that the problem is in wxpython library...

Thanks in advance for your help.

Regards, Pablo Nicolás

Comments

Hi Pablo, what kind of crash is it? Does the "windows has detected a problem" box come up?

JervisW gravatar imageJervisW (Oct 15 '12)

1 answer

Sort by » oldest newest most voted
2

answered Nov 1 '12

jsexauer gravatar image

My guess would be some kind of variable is getting hosed up. When you run a script in PyScripter and then run it again, PyScripter resets Python between the two runs. However, PSSE runs the script the second time from where the first run left off, so all the variables are still in scope.

To test this, run your script, then run the commands below, then run your script again. If it works fine, you know that its because of how your script is leaving the variables when it exits.

import sys
this = sys.modules[__name__]
for n in dir():
    if n[0]!='_': delattr(this, n)
link

Comments

It works! Thank you very much!!! But I close my window with the next instruction: frame.Close(True) How should I close the window?

Pablo Nicolas gravatar imagePablo Nicolas (Nov 2 '12)
1

change the last line to be:

if n[0]!='_' and n!='frame': delattr(this, n)

jsexauer gravatar imagejsexauer (Nov 2 '12)

FYI, my original solution was to prove that the problem is with your variables not clearing between runs. You should figure out why they need to be initialized. Probably you're assuming a var is false because it wasn't declared until that moment in the 1st run, but has a value is set in the 2nd

jsexauer gravatar imagejsexauer (Nov 2 '12)

It's solved. Thank you very much!

Pablo Nicolas gravatar imagePablo Nicolas (Nov 9 '12)

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

Stats

Asked: Oct 15 '12

Seen: 983 times

Last updated: Nov 01 '12