<tfoot id='2BMHf'></tfoot>
      • <bdo id='2BMHf'></bdo><ul id='2BMHf'></ul>

        <small id='2BMHf'></small><noframes id='2BMHf'>

        <legend id='2BMHf'><style id='2BMHf'><dir id='2BMHf'><q id='2BMHf'></q></dir></style></legend>
        <i id='2BMHf'><tr id='2BMHf'><dt id='2BMHf'><q id='2BMHf'><span id='2BMHf'><b id='2BMHf'><form id='2BMHf'><ins id='2BMHf'></ins><ul id='2BMHf'></ul><sub id='2BMHf'></sub></form><legend id='2BMHf'></legend><bdo id='2BMHf'><pre id='2BMHf'><center id='2BMHf'></center></pre></bdo></b><th id='2BMHf'></th></span></q></dt></tr></i><div id='2BMHf'><tfoot id='2BMHf'></tfoot><dl id='2BMHf'><fieldset id='2BMHf'></fieldset></dl></div>
      1. python中是否有任何内置的跨线程事件?

        Are there any built-in cross-thread events in python?(python中是否有任何内置的跨线程事件?)
        <legend id='iIs8v'><style id='iIs8v'><dir id='iIs8v'><q id='iIs8v'></q></dir></style></legend>
        <i id='iIs8v'><tr id='iIs8v'><dt id='iIs8v'><q id='iIs8v'><span id='iIs8v'><b id='iIs8v'><form id='iIs8v'><ins id='iIs8v'></ins><ul id='iIs8v'></ul><sub id='iIs8v'></sub></form><legend id='iIs8v'></legend><bdo id='iIs8v'><pre id='iIs8v'><center id='iIs8v'></center></pre></bdo></b><th id='iIs8v'></th></span></q></dt></tr></i><div id='iIs8v'><tfoot id='iIs8v'></tfoot><dl id='iIs8v'><fieldset id='iIs8v'></fieldset></dl></div>
          <tbody id='iIs8v'></tbody>

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

          <bdo id='iIs8v'></bdo><ul id='iIs8v'></ul>
              <tfoot id='iIs8v'></tfoot>

                • 本文介绍了python中是否有任何内置的跨线程事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  python 中是否有任何内置语法允许我向问题中的特定 python 线程发布消息?就像 pyQt 中的排队连接信号"或 Windows 中的 ::PostMessage().我需要它用于程序部分之间的异步通信:有许多处理网络事件的线程,它们需要将这些事件发布到单个逻辑"线程,该线程以安全的单线程方式转换事件.

                  Is there any built-in syntax in python that allows me to post a message to specific python thread inside my problem? Like 'queued connected signal' in pyQt or ::PostMessage() in Windows. I need this for asynchronous communication between program parts: there is a number of threads that handle network events and they need to post these events to a single 'logic' thread that translates events safe single-threaded way.

                  推荐答案

                  队列 module is python 非常适合您所描述的内容.

                  The Queue module is python is well suited to what you're describing.

                  您可以设置一个在所有线程之间共享的队列.处理网络事件的线程可以使用 queue.put 将事件发布到队列中.逻辑线程将使用 queue.get 从队列中检索事件.

                  You could have one queue set up that is shared between all your threads. The threads that handle the network events can use queue.put to post events onto the queue. The logic thread would use queue.get to retrieve events from the queue.

                  import Queue
                  # maxsize of 0 means that we can put an unlimited number of events
                  # on the queue
                  q = Queue.Queue(maxsize=0)
                  
                  def network_thread():
                      while True:
                          e = get_network_event()
                          q.put(e)
                  
                  def logic_thread():
                      while True:
                          # This will wait until there are events to process
                          e = q.get()
                          process_event(e)
                  

                  这篇关于python中是否有任何内置的跨线程事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Pythonic and efficient way of finding adjacent cells in grid(在网格中查找相邻单元格的 Pythonic 和有效方法)
                  map a hexagonal grid in matplotlib(在 matplotlib 中映射六边形网格)
                  Execute arbitrary python code remotely - can it be done?(远程执行任意 python 代码 - 可以吗?)
                  Python - Plotting colored grid based on values(Python - 根据值绘制彩色网格)
                  Is there a GUI design app for the Tkinter / grid geometry?(是否有 Tkinter/网格几何图形的 GUI 设计应用程序?)
                  tkinter Canvas Scrollbar with Grid?(带有网格的 tkinter 画布滚动条?)
                      <bdo id='kwquZ'></bdo><ul id='kwquZ'></ul>

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

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

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