My problem is that I get exceptions that I cannot explain
Debian 10 (buster)
3.7.3
4.4.1
2 years Python programming experience
2 years Programming experience overall
no - Have used another Python GUI Framework (tkiner, Qt, etc) previously?
EXCEPTION LIST
Exception ignored in: <function Image.__del__ at 0x7f75cf76ed90>
Traceback (most recent call last):
File "/usr/lib/python3.7/tkinter/__init__.py", line 3507, in __del__
self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
RuntimeError: main thread is not in main loop
Exception ignored in: <function Variable.__del__ at 0x7f75cf7d1c80>
Traceback (most recent call last):
File "/usr/lib/python3.7/tkinter/__init__.py", line 332, in __del__
if self._tk.getboolean(self._tk.call("info", "exists", self._name)):
RuntimeError: main thread is not in main loop
RuntimeError: main thread is not in main loop
Exception ignored in: <function Variable.__del__ at 0x7f75cf7d1c80>
Traceback (most recent call last):
File "/usr/lib/python3.7/tkinter/__init__.py", line 332, in __del__
if self._tk.getboolean(self._tk.call("info", "exists", self._name)):
RuntimeError: main thread is not in main loop
Tcl_AsyncDelete: async handler deleted by the wrong thread
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
You're running something multithreaded.
You cannot make any PySimpleGUI calls from a thread.
https://pysimplegui.readthedocs.io/en/latest/#do-not-attempt-to-call-pysimplegui-from-multiple-threads-its-tkinter-based-and-tkinter-has-issues-with-multiple-threads
Our app is multithreaded, but we don't do any calls from a thread to the gui.
You don't do any updates to things in the Window in your threads?
Somehow tkinter is getting called from a thread that is not the main thread.
Sometimes this is caused by objects being deleted in another thread that have some variable or reference to a PySimpleGUI object. When the delete happens in another thread, it calls the tkinter delete code which is what is testing to see if the correct thread is running.
What happens is:
yea, that is sort of what I thought. What happens if you remove passing in this reference to the GUI? there needs to be a real firewall between threads and the GUI with no sharing of data, even if the data is not directly referenced, between the two pieces of code
I implemented your suggested changes by
The error continues to persist.
Damn, that's really sucky.
I'm exploring ways to perform cleanup better on the windows when they are closed.
I'm not 100% sure, but the problem seems to me to be one of Python garbage collect. Stuff is getting around to being deleted a ways after the PySimpleGUI stuff has completed. The result is that the garbage collection, the delete routines withing tkinter are being executed in a different thread than the main thread.
If you search on this error, you'll find it goes WAY back, not just in terms of PySimpleGUI, but many years back. I thought I posted an announcement or an issue somewhere that contained a link or information about this error.
I'm working on this actively.
Can you try deleting the window object when you're done with it? I assume you're only running a single window and not using popups. Popups would need to get deleted too which you won't be able to do.
Anyway, I'll get some experimental code up when I find something.
I don't suppose you have a short piece of code that will demonstrate this?
Can I ask how many windows you open or what popup or debug print calls you make?
If you are making and showing a single window that you close prior to running the code that is generating errors, then you can delete the window, assuming it's held in the variable named window, with this line of code:
del window
Thank you very much for your engagement, I really appreciate it!
I have implemented the following, very simple change thanks to your suggestion:
# window.Close()
del window
This seems to have fixed the issue. I hope, that it also helps you to eradicate the error.
Oh wow.... WOW... like WOW!!!
Thank you very much for sticking in there with me on this. I've modified the code so that a window close will also delete the window object. I'm hoping that will solve a lot of these problems.
WHEW! What a relief.
Please do BOTH the close and the delete.... it should be:
window.Close()
del window
It's important as the close does some calls to tkinter that will not be made if you only delete the object. There are counts for the number of windows open for example.
Please let me know if doing both does NOT work for you.
The combination works great for me!