how to convert code that uses cmp to python3

Terry Reedy tjreedy at udel.edu
Fri Apr 8 02:12:04 EDT 2016


On 4/7/2016 3:32 PM, Marko Rauhamaa wrote:

> I use AVL trees to implement timers. You need to be able to insert
> elements in a sorted order and remove them quickly.
>
> Guido chose a different method to implement timers for asyncio. He
> decided to never remove canceled timers.

In 3.5.1, asyncio.base_events.BaseEventLoop._run_once
has this code to remove cancelled timers when they become too numerous.

         if (sched_count > _MIN_SCHEDULED_TIMER_HANDLES and
             self._timer_cancelled_count / sched_count >
                 _MIN_CANCELLED_TIMER_HANDLES_FRACTION):
             # Remove delayed calls that were cancelled if their number
             # is too high
             new_scheduled = []
             for handle in self._scheduled:
                 if handle._cancelled:
                     handle._scheduled = False
                 else:
                     new_scheduled.append(handle)

             heapq.heapify(new_scheduled)
             self._scheduled = new_scheduled
             self._timer_cancelled_count = 0


-- 
Terry Jan Reedy




More information about the Python-list mailing list