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....@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 
<ma...@pacujo.net<mailto:ma...@pacujo.net>> wrote:
Guido van Rossum <gu...@python.org<mailto:gu...@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.




_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to