[Python-Dev] Event loops, PyOS_InputHook, and Tkinter
"Martin v. Löwis"
martin at v.loewis.de
Thu Nov 10 20:40:04 CET 2005
Michiel Jan Laurens de Hoon wrote:
>>You are missing multi-threading, which is the widely used
>>approach to doing things simultaneously in a single process.
> The problem with threading (apart from potential portability problems)
> is that Python doesn't let us know when it's idle. This would cause
> excessive repainting (I can give you an explicit example if you're
I don't understand how these are connected: why do you need to know
when Python is idle for multi-threaded applications, and why does not
knowing that it is idle cause massive repainting?
Not sure whether an explicit example would help, though; one would
probably need to understand a lot of details of your application. Giving
a simplified version of the example might help (which would do 'print
"Repainting"' instead of actually repainting).
> But there is another solution with threads: Can we let Tkinter run in a
> separate thread instead?
Yes, you can. Actually, Tkinter *always* runs in a separate thread
(separate from all other threads).
> This works, but only if Tkinter is installed, and even then it will give
> poor performance due to the busy-loop with 20 ms sleep in between in
> Tkinter. Furthermore, this will not work with IDLE, because the Python
> thread that handles user commands never enters the Tkinter event loop,
> even if we import Tkinter. AFAIK, there is no easy solution to this.
Here I'm losing track. What is "this" which is no easy solution for?
Why do you need a callback when Python is idle in the first place?
> I may be wrong here, but I'd think that it would be dangerous to run
> Tkinter's event loop when one thread is waiting for another (as happens
> in IDLE).
I don't understand. Threads don't wait for each other. Threads wait for
events (which might be generated by some other thread, of course).
However, there is no problem to run the Tkinter event loop when some
unnrelated thread is blocked.
> Sorry if I'm sounding negative, but we've actually considered many
> different things to get the event loop working for our scientific
> visualization software, and we were never able to come up with a
> satisfactory scheme within the current Python framework.
I really don't see what the problem is. Why does the visualization
framework care that Tkinter is around? Why are the events that the
visualization framework needs to process?
More information about the Python-Dev