Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hi

Here is my take on what might be happening...

When running a Python script from within PSSE, a part of the core PSSE event loop is suspended and waits for the Python script to finish before resuming.

The part of the PSSE that is suspended must be related to updating the UI with fresh data.

Here is how I'd test this

if __name__ == "__main__":
    import time
    print "going to sleep for 2 minutes...try steps 2 - 5" 
    time.sleep(120)

I'd love to have tested this. But I'm travelling at the moment and am without PSSE. Can anyone else confirm or deny that they get similar results using this revised script?

My theory is that for the two minutes the script is sleeping that PSSE will not update its UI and behave similarly to your Tkinter example.

How to deal with this problem

The first method is to run Python from outside PSSE (only calling on the PSSE API from within Python when you need it). Now you won't have the PSSE GUI available.

You could also experiment with running the mainloop in another thread using the threading library in Python (docs).

Unfortunately the first option deals with your problem by removing PSSE's GUI; and the second one is just a line of testing that I'd explore if I had access to PSSE.

If you find anything else out I'd love to hear about it.

Cheers

click to hide/show revision 2
update info about long running process outside of PSSE

Hi

Here is my take on what might be happening...

When running a Python script from within PSSE, a part of the core PSSE event loop is suspended and waits for the Python script to finish before resuming.

The part of the PSSE that is suspended must be related to updating the UI with fresh data.

Here is how I'd test this

if __name__ == "__main__":
    import time
    print "going to sleep for 2 minutes...try steps 2 - 5" 
    time.sleep(120)

I'd love to have tested this. But I'm travelling at the moment and am without PSSE. Can anyone else confirm or deny that they get similar results using this revised script?

My theory is that for the two minutes the script is sleeping that PSSE will not update its UI and behave similarly to your Tkinter example.

How to deal with this problem

(update)

Here is a proof of concept for a spawning a long running process outside of PSSE from inside of PSSE: https://gist.github.com/jtrain/8344157

I've copied the main.py script here.

"""
Main thread

Spawns a new process outside of itself.
"""
import subprocess
from tkFileDialog import askopenfilename

def main():

  childscript = askopenfilename(title="Run which script?")
  subprocess.Popen(
      ["python", childscript],
      creationflags=subprocess.CREATE_NEW_CONSOLE)

  print "finished main"

main()

the secret here is in subprocess with the CREATE_NEW_CONSOLE flag. The first method is to way it works is this

  1. From inside PSSE you run Python from this main.py script.
  2. main.py asks you which file you'd like to open
  3. that child.py file you select will run outside PSSE (only calling of PSSE's control, and the UI becomes responsive again.

@jsexaur mentioned, the trick is now communicating with that external process that it's running. I'll report back when I develop more on the PSSE API from within Python when you need it). Now you won't have the PSSE GUI available.

You could also experiment with running the mainloop in another thread using the threading library in Python (docs).

Unfortunately the first option deals with your problem by removing PSSE's GUI; and the second one is just a line of testing that I'd explore if I had access to PSSE.

If you find anything else out I'd love to hear about it.

Cheers

that front.