In [20]:
import asyncio
import functools
def update(self, new_item):
    priority_level = new_item[0]
    def matching_level(element, priority_level):
        return element[0]==priority_level
    try:
        match_generator = (index for index,element in enumerate(self._queue)
                           if matching_level(element, priority_level))
        matching_index = next(match_generator)
        self._queue[matching_index] = new_item
    except StopIteration:
        self.put_nowait(new_item)
asyncio.PriorityQueue.update = update
q = asyncio.PriorityQueue(maxsize = 15)

In [21]:
def some_func(a):
    print(a)
one = functools.partial(some_func, 1)
two = functools.partial(some_func, 2)
three = functools.partial(some_func, 3)

In [22]:
q.put_nowait((1, one))

In [23]:
q.put_nowait((2,two))

In [24]:
q.update((1,three))

In [26]:
q.update((4, one))

In [27]:
q


Out[27]:
<PriorityQueue at 0x7f4c6d9b9f28 maxsize=15 _queue=[(1, functools.partial(<function some_func at 0x7f4c6de60f28>, 3)), (2, functools.partial(<function some_func at 0x7f4c6de60f28>, 2)), (4, functools.partial(<function some_func at 0x7f4c6de60f28>, 1))]>

In [ ]: