A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-June/025931.html below:

[Python-Dev] Priority queue (binary heap) python code

[Python-Dev] Priority queue (binary heap) python codeFredrik Lundh fredrik@pythonware.com
Tue, 25 Jun 2002 19:03:41 +0200
Gustavo wrote:

>     def put(self, item, block=1, **kw):
>         if block:
>             self.fsema.acquire()
>         elif not self.fsema.acquire(0):
>             raise Full
>         self.mutex.acquire()
>         was_empty = self._empty()
> # <- Priority could be handled here as well.
>         self._put(item, **kw)
>         if was_empty:
>             self.esema.release()
>         if not self._full():
>             self.fsema.release()
>         self.mutex.release()
> 
>     def _put(self, item, **kw):
> # <- But here seems better
>         priority = kw.get("priority", self.defaultpriority)
>         bisect.insort(self.queue, (priority, item))

or better:

    def put(self, item, block=1, priority=None):
        if priority is None:
            priority = self.defaultpriority
        Queue.Queue.put(self, (priority, item), block)

</F>





RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4