Yet another Tkinter and threads question

David LeBlanc whisper at
Tue Sep 17 23:08:21 EDT 2002

> After a short perusal of the group archives I haven't found anything
> answering the following, so here goes:
> I am polishing up the GUI for a client that uses FTP to submit MVS
> jobs to an IBM S/390, and am adding message boxes for exceptional
> circumstances i.e., user mistyped password, connection timeout, etc.
> To prevent locking up the GUI, all submissions spawn a thread, which
> calls a wrapper function around ftplib that does the right
> site-specific hanky-panky to make everything go smoothly. In the
> thread function, the code goes something like this:
> try:
>     submit_job()
> except socket.error:
>     showerror("Socket has barfed")
> except ftplib.error_perm:
>     showerror("You mistyped your password")
> The call to showerror locks the program. Any thoughts? Older posts on
> other threading+GUI questions had mentioned that Tk was not
> thread-safe; has it become so, or is this still a tar-pit?
> Nick
> A.M.D.G.

Yes, very simple. Never ever make a gui call in more then one thread. Make a
single gui thread and have it process messages from the other threads to
report/display problems such as you show. This is pretty much true for every
gui out there, not just Tkinter. Tk is not thread safe, nor wxWindows, nor
Win32. There was talk about making Tk thread safe in some future
incarnation, but it's a big job and I don't know if it's even started yet.


Dave LeBlanc
Seattle, WA USA

More information about the Python-list mailing list