[Python-ideas] Tulip patches

Guido van Rossum guido at python.org
Fri Dec 21 16:57:04 CET 2012


On Fri, Dec 21, 2012 at 6:31 AM, Geert Jansen <geertj at gmail.com> wrote:
>
> Hi,
>
> [if this is not the right forum to post patches for tulip, please
> redirect me to the correct one. There doesn't appear to be a mailing
> list for tulip at the moment. And this list is where most/all of the
> discussion is taking place.]

This is a fine place, but you would make my life even easier by
uploading the patches to codereview.appspot.com, so I can review them
and send comments in-line.

I've given you checkin permissions. Please send a contributor form to
the PSF (http://www.python.org/psf/contrib/contrib-form/).

> Please find attached 4 patches:
>
> 0001-run-fd-callbacks.patch
>
> This patch will run callbacks for readers and writers in the same loop
> iteration as when the fd got ready. Copying from my previous email,
> this is to support the following idiom:
>
>     # handle_read() sets the "ready" flag
>     loop.add_reader(fd, handle_read)
>     while not ready:
>         loop.run_once()
>
> The patch currently dispatches callbacks twice in each iteration, once
> before blocking and once after. I tried to dispatch only once after
> blocking, but this made the SSL transport test hang. The reason is
> that the create_transport task is scheduled with call_soon(), and only
> when the task first runs, a file descriptor is added. So unless you
> dispatch before blocking, this task will never get started.

Interesting. Go ahead and submit.

> 0002-call-every-iteration.patch
>
> This adds a call_every_iteration() method to the event loop. This
> callback runs *before* blocking.

There's one odd thing here: you remove cancelled everytime handlers
*after* already scheduling them. It would seem to make more sense to
schedule them first. Also, a faster way to do this would be

    self._everytime = [handler in self._everytime if not handler.cancelled]

(Even if you iterate from the back, remove() is still O(N), so if half
the handlers are to be removed, your original code would be O(N**2).)

> 0003-fix-typo.patch
> 0004-remove-wrong-comments.patch
>
> Two trivial patches.

Go ahead!

PS. If you want to set up a mailing list or other cleverness I can set
you up as a project admin. (I currently have all patches mailed to me
but we may want to set up a separate list for that.)

--
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list