<legend id='vZR8H'><style id='vZR8H'><dir id='vZR8H'><q id='vZR8H'></q></dir></style></legend>
<i id='vZR8H'><tr id='vZR8H'><dt id='vZR8H'><q id='vZR8H'><span id='vZR8H'><b id='vZR8H'><form id='vZR8H'><ins id='vZR8H'></ins><ul id='vZR8H'></ul><sub id='vZR8H'></sub></form><legend id='vZR8H'></legend><bdo id='vZR8H'><pre id='vZR8H'><center id='vZR8H'></center></pre></bdo></b><th id='vZR8H'></th></span></q></dt></tr></i><div id='vZR8H'><tfoot id='vZR8H'></tfoot><dl id='vZR8H'><fieldset id='vZR8H'></fieldset></dl></div>
    <bdo id='vZR8H'></bdo><ul id='vZR8H'></ul>

    <tfoot id='vZR8H'></tfoot>

    <small id='vZR8H'></small><noframes id='vZR8H'>

        如何在 python 中为 multiprocessing.Queue 实现 LIFO?

        How to implement LIFO for multiprocessing.Queue in python?(如何在 python 中为 multiprocessing.Queue 实现 LIFO?)
        <i id='ap9Ln'><tr id='ap9Ln'><dt id='ap9Ln'><q id='ap9Ln'><span id='ap9Ln'><b id='ap9Ln'><form id='ap9Ln'><ins id='ap9Ln'></ins><ul id='ap9Ln'></ul><sub id='ap9Ln'></sub></form><legend id='ap9Ln'></legend><bdo id='ap9Ln'><pre id='ap9Ln'><center id='ap9Ln'></center></pre></bdo></b><th id='ap9Ln'></th></span></q></dt></tr></i><div id='ap9Ln'><tfoot id='ap9Ln'></tfoot><dl id='ap9Ln'><fieldset id='ap9Ln'></fieldset></dl></div>

            <tbody id='ap9Ln'></tbody>
            <bdo id='ap9Ln'></bdo><ul id='ap9Ln'></ul>
          • <small id='ap9Ln'></small><noframes id='ap9Ln'>

          • <tfoot id='ap9Ln'></tfoot>
                • <legend id='ap9Ln'><style id='ap9Ln'><dir id='ap9Ln'><q id='ap9Ln'></q></dir></style></legend>
                • 本文介绍了如何在 python 中为 multiprocessing.Queue 实现 LIFO?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我了解队列和堆栈之间的区别.但是,如果我生成多个进程并在它们之间发送消息放入 multiprocessing.Queue 我如何首先访问放入队列中的最新元素?

                  I understand the difference between a queue and stack. But if I spawn multiple processes and send messages between them put in multiprocessing.Queue how do I access the latest element put in the queue first?

                  推荐答案

                  你可以使用 多处理管理器 来包装 队列.LifoQueue 做你想做的事.

                  You can use a multiprocessing manager to wrap a queue.LifoQueue to do what you want.

                  from multiprocessing import Process
                  from multiprocessing.managers import BaseManager
                  from time import sleep
                  from queue import LifoQueue
                  
                  
                  def run(lifo):
                      """Wait for three messages and print them out"""
                      num_msgs = 0
                      while num_msgs < 3:
                          # get next message or wait until one is available
                          s = lifo.get()
                          print(s)
                          num_msgs += 1
                  
                  
                  # create manager that knows how to create and manage LifoQueues
                  class MyManager(BaseManager):
                      pass
                  MyManager.register('LifoQueue', LifoQueue)
                  
                  
                  if __name__ == "__main__":
                  
                      manager = MyManager()
                      manager.start()
                      lifo = manager.LifoQueue()
                      lifo.put("first")
                      lifo.put("second")
                  
                      # expected order is "second", "first", "third"
                      p = Process(target=run, args=[lifo])
                      p.start()
                  
                      # wait for lifoqueue to be emptied
                      sleep(0.25)
                      lifo.put("third")
                  
                      p.join()
                  

                  这篇关于如何在 python 中为 multiprocessing.Queue 实现 LIFO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)
                  <tfoot id='yMP3x'></tfoot>

                      • <bdo id='yMP3x'></bdo><ul id='yMP3x'></ul>

                      • <i id='yMP3x'><tr id='yMP3x'><dt id='yMP3x'><q id='yMP3x'><span id='yMP3x'><b id='yMP3x'><form id='yMP3x'><ins id='yMP3x'></ins><ul id='yMP3x'></ul><sub id='yMP3x'></sub></form><legend id='yMP3x'></legend><bdo id='yMP3x'><pre id='yMP3x'><center id='yMP3x'></center></pre></bdo></b><th id='yMP3x'></th></span></q></dt></tr></i><div id='yMP3x'><tfoot id='yMP3x'></tfoot><dl id='yMP3x'><fieldset id='yMP3x'></fieldset></dl></div>

                        <legend id='yMP3x'><style id='yMP3x'><dir id='yMP3x'><q id='yMP3x'></q></dir></style></legend>

                          <small id='yMP3x'></small><noframes id='yMP3x'>

                            <tbody id='yMP3x'></tbody>