mtTkinter doesn't terminate threads

后端 未结 3 2077
执念已碎
执念已碎 2020-12-17 03:10

I need to run some simple function in multi-threading with a Tkinter GUI, so I\'ve tried mtTkinter.

Everything works fine except for a particular: even if I just sta

3条回答
  •  别那么骄傲
    2020-12-17 03:41

    I ran into a similar problem for my application (https://github.com/joecole889/spam-filter). After some investigation, I realized that when I close my application Tkinter (or possibly Matplotlib) uses a threading._DummyThread instance to delete one of the widgets. I have a Matplotlib graph in a Tkinter canvas widget in my application. In any case, it looks like an “image delete” event is added to the event queue and mtTkinter blocks waiting for a response on the responseQueue that never comes.

    I was able to fix the problem by allowing events from instances of threading._DummyThread to run without going through the queue infrastructure of mtTkinter. That is, I changed:

    if threading.currentThread() == self._tk._creationThread:
    

    to

    if (threading.currentThread() == self._tk._creationThread) or \
       isinstance(threading.currentThread(), threading._DummyThread) :
    

    Things seem to be working for me now...hope this helps!

提交回复
热议问题