[Python-ideas] PEP 3156/Tulip: Extensible EventLoop interface

Nick Coghlan ncoghlan at gmail.com
Mon Feb 4 00:19:18 CET 2013


On 4 Feb 2013 07:45, "Greg Ewing" <greg.ewing at canterbury.ac.nz> wrote:
>>
>> On Sat, Feb 2, 2013 at 8:36 PM, Nick Coghlan <ncoghlan at gmail.com <mailto:
ncoghlan at gmail.com>> wrote:
>>
>>     The general idea of using factory functions for transport creation,
>>     even for the "core transports" (like sockets, SSL and pipes) sounds
>>     good to me. I've expressed some concerns previously about the breadth
>>     of the event loop class API, and this would go a long way towards
>>     alleviating them.
>
>
> How would this work, exactly? The implementation of these
> functions will depend on the platform and event loop being
> used, so there still needs to be some kind of dispatching
> mechanism based on the current event loop.

Ben covered that in his original post: the event loop has a registry of
transport factories, keyed by the factory name (e.g.
"mycoolmodule.myneattransport". The factory functions check the event loop
registry for an implementation and use it if they find it. Otherwise, they
fall back to a non-optimised implementation based on the standard event
loop API, or they throw an error indicating that the transport doesn't
support the current event loop.

It's a really elegant design that:
- provides a consistent user experience between "first party" and "third
party" transport implementations, rather than switching arbitrarily from
"event loop method" to "module level function" based on an implementation
detail
- allows an optimised transport implementation to be added to an event loop
without requiring application code to change in order to take advantage of
it and without even requiring cooperation from the event loop developers
- the transport creation API also extends cleanly to the creation of
protocol stacks

A per event loop implementation transport registry makes sense for the same
reason the codec registry makes sense. The only differences are that:
- the different transports may offer different APIs
- the registry isn't global, but specific to each event loop implementation.

Cheers,
Nick.

>
> --
> Greg
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130204/0945bd10/attachment.html>


More information about the Python-ideas mailing list