[Python-ideas] PEP 3156 EventLoop: hide details of iterations and idleness?

Ben Darnell ben at bendarnell.com
Mon Jan 21 23:13:37 CET 2013


While working on proof-of-concept tornado/tulip integration (
https://gist.github.com/4582282), I found a few methods that could not
easily be implemented on top of the tornado IOLoop because they rely on
details that Tornado does not expose.  While it wouldn't be hard to add
support for these methods to Tornado, I would argue that they are
unnecessary and expose implementation details, and so they are good
candidates for removal from this already very broad interface.

First, run_once and call_every_iteration both expose the event loop's
underlying iterations to the application.  The trouble is that the duration
of one iteration is so widely variable that it's not a very useful concept
(and when implementing the EventLoop interface on top of some existing
event loop these methods may not be available).  When is it better to use
run_once instead of just using call_later to schedule a stop after a short
timeout, or call_every_iteration instead of call_repeatedly?

Second, while run_until_idle is convenient (especially for tests), it's
kind of fragile and exposes you to implementation details in the libraries
you use.  If anyone uses call_repeatedly, run_until_idle won't work unless
that callback is cancelled.  As an example, I once had to introduce
Tornado's equivalent of call_repeatedly in a library to work around a bug
in libcurl.  If had been using run_until_idle in my tests, they'd have all
broken.  I think we should either remove run_until_idle or add a "daemon"
flag to call_repeatedly (and call_later, and possibly others).

-Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130121/31c068c5/attachment.html>


More information about the Python-ideas mailing list