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

Ronald Oussoren ronaldoussoren at mac.com
Mon Nov 14 19:19:14 CET 2005


On 14-nov-2005, at 16:00, skip at pobox.com wrote:

>
>     Ronald> ... except when the GUI you're using doesn't expose (or  
> even
>     Ronald> use) a file descriptor that you can use with select.  
> Not all the
>     Ronald> world is Linux.
>
> Can you be more specific?  Are you referring to Windows?

I was thinking of MacOS X. It does have a eventloop, but doesn't  
expose a
file descriptor to the user and might not even use one.

Adding Python's input to the runloop of the GUI might be easier (e.g.  
feed
the stdin filedescriptor to the GUI-toolkit-du-jour and process  
information
when that runloop tells you that data is present). We have an example  
of that
in the PyObjC source tree.

I'd say either choice won't be very good. The problem is that you must
interleave the execution of Python code with running the eventloop to  
get
nice behaviour, which suggests threading to me. If you don't interleave
you can easily block the GUI while Python code is executing.

> I'm not suggesting
> you'd be able to use the same exact implementation on Unix and non- 
> Unix
> platforms.  You might well have to do different things across  
> different
> platforms.  Hopefully it would look the same to the programmer  
> though, both
> across platforms and across toolkits.

Twisted anyone? ;-) ;-)

> I can't imagine any of the X-based
> widget toolkits on Unix systems would use anything other than select 
> () on a
> socket at the bottom.

I'd be very surprised if an X-based toolkit didn't use a select-loop  
somewhere.

Ronald

>
> Skip



More information about the Python-Dev mailing list