[Tkinter-discuss] Proposal for thread-safe Tkinter
Allen.Taylor at mdacorporation.com
Fri Oct 24 21:31:44 CEST 2008
The versions of Python and Tk used are the default packages installed on Linux (Ubuntu 6.06 LTS). I don't know whether the default install is compiled with --enable-threads or not. So, mtTkinter seems to be handy if you want to use the default installed packages?
>>> "Guilherme Polo" <ggpolo at gmail.com> 2008-10-24 15:00 >>>
On Thu, Oct 23, 2008 at 5:49 PM, Allen Taylor
<Allen.Taylor at mdacorporation.com> wrote:
> I was given the task of upgrading a Python/Tkinter GUI application to the
> latest versions of Python and Tk. After a while, I realized that the
> application had not been written in a thread-safe manner. Multiple threads
> would simply use the Tk object directly. The application apparently ran fine
> (i.e., didn't crash!) using older versions of Python (2.2) and Tk (8.3), but
> it started to have serious problems (i.e., crashing) after using the latest
Did you compile these new tcl/tk versions with --enable-threads ? That
is where the problem lies in _tkinter currently. In a tk.call it
checks if python was compiled with threads, but if tcl wasn't compiled
with threads support too, _tkinter acts like single threaded and then
you get these crashes (this happens in other places there too).
> The problem is that there isn't enough budget to fix the whole application.
> So, I invested a bit of time to develop mtTkinter, a thread-safe version of
> Tkinter. Importing mtTkinter actually modifies the original Tkinter in such
> a way to make it thread-safe, recognizing and diverting out-of-thread calls
> to the Tk object creation thread via a queue and an 'after' event. I think
> it works quite well, requiring basically no changes to the application other
> than to import mtTkinter instead of (or in addition to) Tkinter. Even
> packages that use Tkinter (e.g., Pmw) benefit.
> I would like to contribute this module (single file, about 160 lines) to the
> Python community, but I don't know how. I'm new to Python and am not
> initiated in the deep Pythonic developer world. Can someone give me some
> pointers? Many thanks.
I have read your other email where you posted the code for this module
but let me comment on it here too.
It is nice that it fixes the problem mentioned above ;)
And I believe _tkinter deserves a fix in this respect, I don't think
it was intended to not work correctly when python has thread support
and tcl/tk doesn't.
> Allen B. Taylor
> 9445 Airport Road
> Brampton, ON L6S 4J3
> 905-790-2800 ext. 4350
> allen.taylor at mdacorporation.com
-- Guilherme H. Polo Goncalves
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tkinter-discuss