[Tutor] Tkinter threads

Mats Wichmann mats at wichmann.us
Mon Mar 7 19:23:54 EST 2022


On 3/7/22 16:58, Phil wrote:
> Alan mentioned the use of threads when replying to the Class access
> rules thread.
> 
>  # ideally put this loop in a thread
> 
> From what I understand, and I haven't researched this topic deeply,
> tkinter is not multithreaded. How might I put a loop into it's own thread?
> 
> I have a project (Conway's game of life) where either the GUI or the
> calculation code needs to be in independent threads. The GUI is very
> sluggish to unresponsive while cell generations are being calculated.
> This is a wxpython project, perhaps tkinter handles threads in a way
> that's more understandable to the amateur programmer.
> 

Just as a general comment: not likely.  Threading in Python has to live
with the famous GIL - which is, basically, that whenever you're
executing Python code that will be modifying object state, the global
interpreter lock is used to keep other Python threads from messing with
things. You say the GUI is unresponsive while calculation is in progress
- but does this actually matter?  If you don't know the next generation
to display, then there's nothing new to display, so you might as well
wait a bit, right?

Conway in Python is a pretty well studied topic, just FWIW (as In,
people use it as an interview question. [[Deep Sigh]])... but usually
people leave the display part of it, because getting the computation
right, and efficient, is usually what's considered the interesting problem.



More information about the Tutor mailing list