heapq question

Miles semanticist at gmail.com
Sun Jul 13 22:40:30 CEST 2008


On Sun, Jul 13, 2008 at 4:16 PM, Duncan Booth
<duncan.booth at invalid.invalid> wrote:
> "Giampaolo Rodola'" <gnewsg at gmail.com> wrote:
>> I understand that heapq is not that efficient to implement timeouts as
>> I thought at first.
>> It would have been perfect if there were functions to remove arbitrary
>> elements withouth needing to re-heapify() the heap every time.
>>
> There could be suitable functions, but there aren't any.
> ...
> Bottom line though is that heaps aren't really suitable for timeouts.

I would argue that heaps in general are ideally suited for timeouts;
it's just that the Python heapq implementation is lacking if you ever
need to cancel a timeout before it expires.

-Miles



More information about the Python-list mailing list