[Python-Dev] Towards native fileevents in Python (Was Re: Python
multiplexing is too hard)
Ka-Ping Yee
ping@lfw.org
Mon, 22 May 2000 09:29:54 -0700 (PDT)
On Mon, 22 May 2000, Cameron Laird wrote:
>
> Tcl's event model has been more successful than
> any of you probably realize. You deserve to know
> that.
Events are a very powerful concurrency model (arguably
more reliable because they are easier to understand
than threads). My friend Mark Miller has designed a
language called E (http://www.erights.org/) that uses
an event model for all object messaging, and i would
be interested in exploring how we can apply those ideas
to improve Python.
> Should Python have an event model? I'm not con-
> vinced.
Indeed. This would be a huge core change, way too
large to be feasible. But i do think it would be
excellent to simply provide more facilities for
helping people use whatever model they want, and
given the toolkit we let people build great things.
What you described sounded like it could be implemented
fairly easily with some functions like
register(handle, mode, callback)
or file.register(mode, callback)
Put 'callback' in a dictionary of files
to be watched for mode 'mode'.
mainloop(timeout)
Repeat (forever or until 'timeout') a
'select' on all the files that have been
registered, and do calls to the callbacks
that have been registered.
Presumably there would be some exception that a
callback could raise to quietly exit the 'select'
loop.
1. How does Tcl handle exiting the loop?
Is there a way for a callback to break
out of the vwait?
2. How do you unregister these callbacks in Tcl?
-- ?!ng