[Python-ideas] libuv based eventloop for tulip experiment
Saúl Ibarra Corretgé
saghul at gmail.com
Mon Jan 28 23:48:54 CET 2013
Hi all!
I haven't been able to keep up with all the tulip development on the
mailing list (hopefully I will now!) so please excuse me if something I
mention has already been discussed.
For those who may not know it, libuv is the platform layer library for
nodejs, which implements a uniform interface on top of epoll, kqueue,
event ports and iocp. I wrote Python bindings [1] for it a while ago,
and I was very excited to see Tulip, so I thought I'd give this a try.
Here [2] is the source code, along with some notes I took during the
implementation.
I know that the idea is not to re-implement the PEP itself but for
people to create different EventLoop implementations. On rose I bundled
tulip just to make a single package I could play with easily, once tulip
makes it to the stdlib only the EventLop will remain.
Here are some thoughts (in no particular order):
- add_connector / remove_connector seem to be related to Windows, but
being exposed like that feels a bit like leaking an implementation
detail. I guess there was no way around it.
- libuv implements a type of handle (Poll) which provides
level-triggered file descriptor polling which also works on Windows,
while being highly performant. It uses something called AFD Polling
apparently, which is only available on Windows >= Vista, and a select
thread on XP. I'm no Windows expert, but thanks to this the API is
consistent across all platforms, which is nice. mAybe it's worth
investigating? [3]
- The transport abstraction seems quite tight to socket objects. pyuv
provides a TCP and UDP handles, which provide a completion-style API and
use a better approach than Poll handles. They should give better
performance since EINTR in handled internally and there are less
roundtrips between Python-land and C-land. Was it ever considered to
provide some sort of abstraction so that transports can be used on top
of something other than regular sockets? For example I see no way to get
the remote party from the transport, without checking the underlying socket.
Thanks for reading this far and keep up the good work.
Regards,
[1]: https://github.com/saghul/pyuv
[2]: https://github.com/saghul/rose
[3]: https://github.com/joyent/libuv/blob/master/src/win/poll.c
--
Saúl Ibarra Corretgé
http://saghul.net/blog | http://about.me/saghul
More information about the Python-ideas
mailing list