On Wed, May 23, 2012 at 9:32 PM, Giampaolo Rodolà
Including an established async IO framework such as Twisted, gevent or Tornado in the Python stdlib has always been a controversial subject. PEP-3153 (http://www.python.org/dev/peps/pep-3153/) tried to face this problem in the most agnostic way as possible, and it's a good starting point IMO. Nevertheless, it's still vague about what the actual API should look like and AFAIK it remained stagnant so far.
There's one thing in the whole async stack which is basically the same for all implementations though: the poller/reactor. Could it make sense to add something similar to select module? Differently from PEP-3153, providing such a layer on top of select(), poll() & co. is easier and could possibly be an incentive to avoid such code duplication.
I'm coming up with this because I recently did something similar in pyftpdlib as an hack on top of asyncore to add support for epoll() and kqueue(), using the excellent Tornado's io loop as source of inspiration: http://code.google.com/p/pyftpdlib/issues/detail?id=203 http://code.google.com/p/pyftpdlib/source/browse/trunk/pyftpdlib/lib/ioloop....
The way I imagine it:
import select dir(select) [..., 'EpollPoller', 'PollPoller', 'SelectPoller', 'KqueuePoller'] poller = select.EpollPoller() poller.register(fd, handler, poller.READ | poller.WRITE) poller.socket_map {2 :
} poller.modify(fd, poller.READ) poller.poll() # will call handler.handle_read_event() if/when it's the case ^C KeyboardInterrupt poller.remove(fd) poller.close() The handler is supposed to provide 3 methods: - handle_read_event - handle_write_event - handle_error_event
Users willing to support multiple event loops such as wx, gtk etc can do:
while 1: ... poller.poll(timeout=0.1, blocking=False) ... otherpoller.poll()
Basically, this would be the whole API.
Thoughts?
Frankly, I don't think this deserves a PEP at all, or even to consider one *yet*. Building a new API and a new library from scratch seems a frail comparison to testing a library in the real world, it having real uses, and then being incorporated into the stdlib. The problem here, of course, is that all the real-world solutions (ie, Twisted) include far more than the reactor.
--- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ http://code.google.com/p/pysendfile/ _______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
-- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://techblog.ironfroggy.com/ Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy