-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plot windows close automatically #15
Comments
Here is a simple example that demonstrates this behavior:
If you replace
|
Daniel, There are a few reasons that this might happen, and some of it depends on what environment you are running in. The first thing that comes to mind is that windows sometimes close in Python due to how the garbage collector works. Basically, Python "cleans up after itself" by keeping track of references to objects. If an object as no references referring to it, the garbage collector recognizes that nothing is referencing the value anymore, and it will go delete the object from memory. In the context of a GUI window, this will generally trigger the window's destructor, which closes the window. So my first suggestion would be to assign the output from geometry.plot() to a variable and see if the window still closes. Otherwise there are various environment reasons why a window might not pop up or might close. This could depend on if you are using IPython or not, if there is a QApplication running already in the background, or other things. In the referenced issue, they talk about the Python script ending because the opening of the window does not block the progress of the script, and when the script ends, the Python program terminates, and the operating system cleans up after it, meaning again the window is closed and removed from memory. Can you let me know what kind of environment you are running? That would help me debug a bit more. As an example, I use Spyder most of the time, and Spyder runs in an interactive terminal, so if I run a script, when it finishes it lands me back in my interactive terminal, so the window is not closed automatically. Everything works for me as expected with a fresh Python 3.13.1 install (just installed tonight) on my Windows laptop, after (as an aside, your coordinate system transformation matrix looks kind of strange, because your local X and local Y directions are both along global X. I therefore changed the transformation matrix in your script from Note that if I instead run the script instead in an external terminal (e.g. via cmd), the window closes as soon as the Python script ends, because nothing is blocking the script from ending, and when the program ends, all memory used by the program is cleared. The |
I am using VS Code on Windows at the moment. I will be using the code on Linux in the future so maybe this wouldn't be an issue if it's just a Windows thing. I appreciate you taking a look at this for me! Also, I did try assigning a variable to the plotter variable returned by the .plot() method and it didn't change the behavior. I also tried assigning that as a global variable to no effect. |
I don't use VSCode, because I find Spyder is better for interactively working with the data, which is the use-case I typically use with SDynPy. However, I talked to my colleague who uses VSCode, and it looks like there are a couple options, depending on what you want to do with your code. The primary issue you're seeing is that your script is ending, and so the operating system is cleaning up after the process and ends up deleting your window.
and then after you do the plot you can do
This method will block execution of the script until all windows are closed, at which point, it will unblock and the script will end. This has the disadvantage of being blocking, so you cannot further work with your variables in an interactive way while the window is open, and then your variables will be destroyed after the windows are closed due to the script ending.
|
Hi Dan, thank you for your help with this. I'll give your suggestions a try. |
Hi Dan,
First off, you built a great package. I am having issues using the
.plot()
and.plot_coordinate()
methods. The plot windows open for a fraction of a second then close automatically. I think I am seeing similar behavior as described in pyvista/pyvista-support#139. Just curious if you have run into this before.Thanks,
Daniel
The text was updated successfully, but these errors were encountered: