[LWN Logo]

From: Guido van Rossum <guido@CNRI.Reston.Va.US>
Subject: Re: Q: Interval Timers and Tkinter
Date: Wed, 9 Sep 1998 14:21:58 GMT

> The client is implemented in three threads: 1 sends the timed UDP
> messages, 2 receives the TCP messages and prints them to stdout, the
> 3rd (main) thread blocks on raw_input(). Therefore, when I hit
> RETURN on the keyboard, the other threads are killed and the sockets
> are closed and the script exits.

> I then tried to replace the raw_input with a tkMessageBox.showinfo()
> (on Win95/NT). I expected the main thread to block waiting for me to
> click the OK button, but apparently all three threads blocked! Why
> did the Tk() event loop in one thread seem to block the other
> threads? What am I missing? Is there a description of what
> Tk().mainloop() does?

> I eventually want the Tk GUI -- in its own thread -- to modify the
> contents of the UDP messages. Thanks for any help, again.

If you can wait until 1.5.2 is out publicly, you don't need to do
anything.  In 1.5.1 and before, Tk().mainloop() holds on to the Python
interpreter lock, thereby preventing all your threads from running.
In 1.5.2, it will release the lock.

With 1.5.1, you can get the same effect by a simple loop like

	while 1:
	    root.update()
	    time.sleep(0.02)

This will use very little CPU time yet is responsive enough to events.

--Guido van Rossum (home page: http://www.python.org/~guido/)