multithreading and Tkinter

Aahz aahz at pythoncraft.com
Sun Mar 31 20:23:29 EST 2002


In article <Xns91E2A4FE99EA8JamesLLugojcom at 216.148.53.85>,
James Logajan  <JamesL at Lugoj.com> wrote:
>martin at v.loewis.de (Martin v. Loewis) wrote:
>>
>>  [ On a thread signalling the Tkinter mainloop thread: ]
>> If you want to delete the need for an after() method altogether, you
>> could register an after_idle callback. You can do that from a
>> different thread; Tkinter will call the after_idle callback from the
>> same thread that runs the mainloop.
>
>Has anyone ever tried using after_idle in a worker thread as a way to 
>signal a Tkinter mainloop thread? I'm wondering if this proposal is 
>really thread safe, since technically a worker thread is making a call to 
>Tk (even if it is nothing more than registering a callback) while the 
>mainloop thread may also be in the process of making calls to Tk. I haven't 
>tried it but have been considering it, but wanted to know if this was a 
>reasonable solution.

In theory, yes.  Whenever your worker thread is active, it holds the GIL
and things are safe -- sort of.  The problem is that once you've called
after_idle, it's possible for the GIL to switch away unless after_idle
is a C function that does not release the GIL.  So you'll have to do
some poking around in Tkinter to find out.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Why is this newsgroup different from all other newsgroups?



More information about the Python-list mailing list