[Python-Dev] Event loops, PyOS_InputHook, and Tkinter

Michiel Jan Laurens de Hoon mdehoon at c2b2.columbia.edu
Mon Nov 14 02:39:36 CET 2005


Greg Ewing wrote:

>Michiel Jan Laurens de Hoon wrote:
>  
>
>>Greg Ewing wrote:
>>    
>>
>>>How about running your event loop in a separate thread?
>>>      
>>>
>>I agree that this works for some extension modules, but not very well 
>>for extension modules for which graphical performance is critical
>>    
>>
>
>I don't understand. If the main thread is idle, your thread
>should get all the time it wants.
>
>I'd actually expect this to give better interactive response,
>since you aren't doing busy-wait pauses all the time -- the
>thread can wake up as soon as an event arrives for it.
>  
>
This is exactly the problem. Drawing one picture may consist of many 
Python commands to draw the individual elements (for example, several 
graphs overlaying each other). We don't know where in the window each 
element will end up until we have the list of elements complete. For 
example, the axis may change (see my example to Martin). Or, if we're 
drawing a 3D picture, then one element may obscure another.

Now, if we have our plotting extension module in a separate thread, the 
window will be repainted each time a new element is added. Imagine a 
picture of 1000 elements: we'd have to draw 1+2+...+1000 times.

So this is tricky: we want repainting to start as soon as possible, but 
not sooner. Being able to hook into Python's event loop allows us to do so.


--Michiel.

-- 
Michiel de Hoon
Center for Computational Biology and Bioinformatics
Columbia University
1150 St Nicholas Avenue
New York, NY 10032




More information about the Python-Dev mailing list