Martin v. Löwis wrote: >Michiel Jan Laurens de Hoon wrote: > > >>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 >>interested). >> >> >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). > > As an example, consider a function plot(y,x) that plots a graph of y as a function of x.
If I use threading, and Python doesn't let us know when it's idle, then the plot function needs to invalidate the window to trigger repainting. Otherwise, the event loop doesn't realize that there is something new to plot. Now if I want to draw two graphs: def f(): x = arange(1000)*0.01 y = sin(x) plot(y,x) plot(2*y,x) and I execute f(), then after the first plot(y,x), I get a graph of y vs. x with x between 0 and 10 and y between -1 and 1. After the second plot, the y-axis runs from -2 to 2, and we need to draw (y,x) as well as (2*y,x). So the first repainting was in vain. If, however, Python contains an event loop that takes care of events as well as Python commands, redrawing won't happen until Python has executed all plot commands -- so no repainting in vain here. I agree with you though that threads are a good solution for extension modules for which a standard event loop is not suitable, and for which graphics performance is not essential -- such as Tkinter (see my next post). --Michiel. -- Michiel de Hoon Center for Computational Biology and Bioinformatics Columbia University 1150 St Nicholas Avenue New York, NY 10032 _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com