[Python-Dev] collections.sortedtree

Kristján Valur Jónsson kristjan at ccpgames.com
Thu Mar 27 10:36:10 CET 2014


for our stackless socket framework we have the same issue.
Windows provides an opaque timer system where a timer can be cancelled by handle.  But on linux one has to
craft one's own.

One thing with this particular use case is that a heapq is overkill for network timer.  . For network timers a granularity of one
second should typically be sufficient.  Thus, one can implement a map of future times (in quantisized time, e.g. whole seconds) to sets of timers.
A timer is then keyed by its quantisized due time plus its callback.  Cancellation can then be O(1).

From: Python-Dev [mailto:python-dev-bounces+kristjan=ccpgames.com at python.org] On Behalf Of Guido van Rossum
Sent: 26. mars 2014 21:42
To: Marko Rauhamaa
Cc: Python-Dev
Subject: Re: [Python-Dev] collections.sortedtree

I haven't felt it, heapq feels natural to me for this use case. :-)
I'm aware of the issue of frequent cancelled timers, but chose to wait and see rather than preemptively fix it (only so many hours in a day). IIRC pyftplib has a clever cleanup algorithm that we can easily add if that usage pattern becomes popular.

On Wed, Mar 26, 2014 at 2:36 PM, Marko Rauhamaa <marko at pacujo.net<mailto:marko at pacujo.net>> wrote:
Guido van Rossum <guido at python.org<mailto:guido at python.org>>:

> Actually, the first step is publish it on PyPI, the second is to get a
> fair number of happy users there. The bar for getting something
> included into the stdlib is pretty high -- you need to demonstrate
> that there is a need *and* that having it as a 3rd party module is a
> problem.
I hear you about the process.

About the need part, I'm wondering if you haven't felt it in
implementing the timers for asyncio. I have had that need in several
network programming projects and have ended up using my AVL tree
implementation (C and Python).

Well, time will tell if frequent canceled timers end up piling up the
heap queue.




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140327/a7fac0a4/attachment.html>


More information about the Python-Dev mailing list