Threads -- play well with others? If not, what instead?

Gordon McMillan gmcm at hypernet.com
Mon Jun 12 15:09:31 EDT 2000


Russell E. Owen wrote:

>David Beazley's excellent "Python Essential Reference" says in the 
>section on threads: "In addition, many of Python's most popular 
>extensions such as Tkinter may not work properly in a threaded 
>environment."

>I assume it's true, but it was quite a bombshell. I was hoping to write 
>a networked GUI client, hence:
>- read data from a socket and fill in a GUI display
>- accept input from the user and write data to the socket
>I assumed I'd use two threads, one for input, one for output. Now I have 
>no idea what to do. Any suggestions?

It's probably less true now (1.5.2) than when David wrote that.

If you keep all the GUI in one thread (the main thread) it should work 
fine. That means having some kind of inter-thread queue. Use idle time or a 
timer in the GUI thread, and check the queue when it fires.

- Gordon



More information about the Python-list mailing list