Forum: Poser Python Scripting


Subject: Problem exiting script

fivecat opened this issue on Sep 27, 2008 · 6 posts


fivecat posted Sat, 27 September 2008 at 1:39 PM

I noticed that a few of my scripts seem to leave some process running that pegs my processor until I exit out of Poser 7. I did some experimenting and found out that: 1. It happens only with my scripts that use a selectable listbox. 2. It happens only on exiting the script, whether using the button that calls command master.destroy or the "x" close on the window. Any ideas on what is happening here?


fivecat posted Sat, 27 September 2008 at 3:46 PM

Okay, any script using the tKinter listbox seems to do the same.


adp001 posted Sun, 28 September 2008 at 9:39 AM

Sounds like a pointer to something inside your script is left active after your script ends.
Background: Python is allways active and any script started is working in the same Python namespace. There is no "reset" after your script stops.

Try this: Start any script (probably one using a listbox). Exit the script. Create and run a new script containing:

**print "LEFT OVERS"
print "Globalsn",globals()

**You will see a list of objects/variables left over from the previously started script.

Better use classes. If you declare most of your script in class myApp, after

root=Tk()
app=myApp(root)
root.mainloop()
del app
del root

All your objects should be deleted via Pythons garbage collector.




fivecat posted Sun, 28 September 2008 at 12:21 PM

Okay, I'm using classes, and adding the two "del" lines prevents the problem as long as I use the close button on the script window. Right now I'm using this: self.button = Button(frame, text="DONE", fg="red", command=master.destroy) to exit the script. What is a better way to do this than just calling master.destroy?


adp001 posted Sun, 28 September 2008 at 2:43 PM

If you close your script window, you interrupt Tkinter with whatever it does. But before the window is closed, Tkinter fires an event. Catch this event, call your "clean-up" and you are done:

<pre class="python wide">
root.protocol(<span class="pystring">"WM_DELETE_WINDOW"</span>, myApp.master.destroy)



fivecat posted Sun, 28 September 2008 at 6:21 PM

Thank you for your help, it has been very much appreciated.