久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

      1. <legend id='GMQsI'><style id='GMQsI'><dir id='GMQsI'><q id='GMQsI'></q></dir></style></legend>

      2. <i id='GMQsI'><tr id='GMQsI'><dt id='GMQsI'><q id='GMQsI'><span id='GMQsI'><b id='GMQsI'><form id='GMQsI'><ins id='GMQsI'></ins><ul id='GMQsI'></ul><sub id='GMQsI'></sub></form><legend id='GMQsI'></legend><bdo id='GMQsI'><pre id='GMQsI'><center id='GMQsI'></center></pre></bdo></b><th id='GMQsI'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='GMQsI'><tfoot id='GMQsI'></tfoot><dl id='GMQsI'><fieldset id='GMQsI'></fieldset></dl></div>
        <tfoot id='GMQsI'></tfoot>

      3. <small id='GMQsI'></small><noframes id='GMQsI'>

        我可以在 Pool.imap 調(diào)用的函數(shù)中使用多處理隊列嗎

        Can I use a multiprocessing Queue in a function called by Pool.imap?(我可以在 Pool.imap 調(diào)用的函數(shù)中使用多處理隊列嗎?)
            <bdo id='6t0L9'></bdo><ul id='6t0L9'></ul>

            <small id='6t0L9'></small><noframes id='6t0L9'>

              <i id='6t0L9'><tr id='6t0L9'><dt id='6t0L9'><q id='6t0L9'><span id='6t0L9'><b id='6t0L9'><form id='6t0L9'><ins id='6t0L9'></ins><ul id='6t0L9'></ul><sub id='6t0L9'></sub></form><legend id='6t0L9'></legend><bdo id='6t0L9'><pre id='6t0L9'><center id='6t0L9'></center></pre></bdo></b><th id='6t0L9'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='6t0L9'><tfoot id='6t0L9'></tfoot><dl id='6t0L9'><fieldset id='6t0L9'></fieldset></dl></div>
                  <tbody id='6t0L9'></tbody>

              • <legend id='6t0L9'><style id='6t0L9'><dir id='6t0L9'><q id='6t0L9'></q></dir></style></legend>

              • <tfoot id='6t0L9'></tfoot>
                • 本文介紹了我可以在 Pool.imap 調(diào)用的函數(shù)中使用多處理隊列嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我正在使用 python 2.7,并嘗試在自己的進程中運行一些 CPU 繁重的任務(wù).我希望能夠?qū)⑾l(fā)送回父進程,以使其了解進程的當(dāng)前狀態(tài).多處理隊列似乎很適合這個,但我不知道如何讓它工作.

                  I'm using python 2.7, and trying to run some CPU heavy tasks in their own processes. I would like to be able to send messages back to the parent process to keep it informed of the current status of the process. The multiprocessing Queue seems perfect for this but I can't figure out how to get it work.

                  所以,這是我的基本工作示例減去隊列的使用.

                  So, this is my basic working example minus the use of a Queue.

                  import multiprocessing as mp
                  import time
                  
                  def f(x):
                      return x*x
                  
                  def main():
                      pool = mp.Pool()
                      results = pool.imap_unordered(f, range(1, 6))
                      time.sleep(1)
                  
                      print str(results.next())
                  
                      pool.close()
                      pool.join()
                  
                  if __name__ == '__main__':
                      main()
                  

                  我嘗試以多種方式傳遞隊列,但它們收到錯誤消息RuntimeError:隊列對象只能通過繼承在進程之間共享".這是我根據(jù)我找到的早期答案嘗試的方法之一.(我在嘗試使用 Pool.map_async 和 Pool.imap 時遇到了同樣的問題)

                  I've tried passing the Queue in several ways, and they get the error message "RuntimeError: Queue objects should only be shared between processes through inheritance". Here is one of the ways I tried based on an earlier answer I found. (I get the same problem trying to use Pool.map_async and Pool.imap)

                  import multiprocessing as mp
                  import time
                  
                  def f(args):
                      x = args[0]
                      q = args[1]
                      q.put(str(x))
                      time.sleep(0.1)
                      return x*x
                  
                  def main():
                      q = mp.Queue()
                      pool = mp.Pool()
                      results = pool.imap_unordered(f, ([i, q] for i in range(1, 6)))
                  
                      print str(q.get())
                  
                      pool.close()
                      pool.join()
                  
                  if __name__ == '__main__':
                      main()
                  

                  最后,0 適應(yīng)度方法(使其成為全局)不會生成任何消息,它只是鎖定.

                  Finally, the 0 fitness approach (make it global) doesn't generate any messages, it just locks up.

                  import multiprocessing as mp
                  import time
                  
                  q = mp.Queue()
                  
                  def f(x):
                      q.put(str(x))
                      return x*x
                  
                  def main():
                      pool = mp.Pool()
                      results = pool.imap_unordered(f, range(1, 6))
                      time.sleep(1)
                  
                      print q.get()
                  
                      pool.close()
                      pool.join()
                  
                  if __name__ == '__main__':
                      main()
                  

                  我知道它可能會直接與 multiprocessing.Process 一起使用,并且還有其他庫可以實現(xiàn)這一點,但我不想放棄非常適合的標準庫函數(shù),直到我確定它不是只是我缺乏知識使我無法利用它們.

                  I'm aware that it will probably work with multiprocessing.Process directly and that there are other libraries to accomplish this, but I hate to back away from the standard library functions that are a great fit until I'm sure it's not just my lack of knowledge keeping me from being able to exploit them.

                  謝謝.

                  推薦答案

                  訣竅是將 Queue 作為參數(shù)傳遞給初始化程序.似乎適用于所有 Pool 調(diào)度方法.

                  The trick is to pass the Queue as an argument to the initializer. Appears to work with all the Pool dispatch methods.

                  import multiprocessing as mp
                  
                  def f(x):
                      f.q.put('Doing: ' + str(x))
                      return x*x
                  
                  def f_init(q):
                      f.q = q
                  
                  def main():
                      jobs = range(1,6)
                  
                      q = mp.Queue()
                      p = mp.Pool(None, f_init, [q])
                      results = p.imap(f, jobs)
                      p.close()
                  
                      for i in range(len(jobs)):
                          print q.get()
                          print results.next()
                  
                  if __name__ == '__main__':
                      main()
                  

                  這篇關(guān)于我可以在 Pool.imap 調(diào)用的函數(shù)中使用多處理隊列嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多處理模塊的 .join() 方法到底在做什么?)
                  Passing multiple parameters to pool.map() function in Python(在 Python 中將多個參數(shù)傳遞給 pool.map() 函數(shù))
                  multiprocessing.pool.MaybeEncodingError: #39;TypeError(quot;cannot serialize #39;_io.BufferedReader#39; objectquot;,)#39;(multiprocessing.pool.MaybeEncodingError: TypeError(cannot serialize _io.BufferedReader object,)) - IT屋-程序員軟件開
                  Python Multiprocess Pool. How to exit the script when one of the worker process determines no more work needs to be done?(Python 多進程池.當(dāng)其中一個工作進程確定不再需要完成工作時,如何退出腳本?) - IT屋-程序員
                  How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊列引用傳遞給 pool.map_async() 管理的函數(shù)?)
                  yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯誤的另一個混淆,“模塊對象沒有屬性“f)

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

                  <tfoot id='xCRB3'></tfoot>
                    <bdo id='xCRB3'></bdo><ul id='xCRB3'></ul>
                      <tbody id='xCRB3'></tbody>
                  • <legend id='xCRB3'><style id='xCRB3'><dir id='xCRB3'><q id='xCRB3'></q></dir></style></legend>
                    • <i id='xCRB3'><tr id='xCRB3'><dt id='xCRB3'><q id='xCRB3'><span id='xCRB3'><b id='xCRB3'><form id='xCRB3'><ins id='xCRB3'></ins><ul id='xCRB3'></ul><sub id='xCRB3'></sub></form><legend id='xCRB3'></legend><bdo id='xCRB3'><pre id='xCRB3'><center id='xCRB3'></center></pre></bdo></b><th id='xCRB3'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='xCRB3'><tfoot id='xCRB3'></tfoot><dl id='xCRB3'><fieldset id='xCRB3'></fieldset></dl></div>

                          1. 主站蜘蛛池模板: 国产精品99久久久久久久久 | 三级在线播放 | 狠狠做深爱婷婷久久综合一区 | 国产99对白在线播放 | 精品一区二区三区视频 | 日韩欧美在线观看视频 | 日韩高清精品免费观看 | 日韩一区二区三区在线 | 天天色小说| 黄色综合网| 欧美成人黄色 | 国产欧美在线播放 | 四虎影院在线免费观看 | 欧美高清一区二区 | 国产精品福利一区 | 91日韩欧美 | 欧美性猛交xxxx黑人猛交 | 三级黄网站 | 美女国产精品 | 午夜免费av| 免费看黄色一级片 | 亚洲欧美日韩在线 | 天天草夜夜草 | 九九热视频在线观看 | 中文字幕在线观看网站 | 黄色一及片 | 夜夜骑夜夜操 | 少妇高潮毛片 | 免费观看的黄色网址 | 国产精品久久一区二区三区 | 亚洲精品久久久 | 成人黄性视频 | 91成人小视频 | 91精品国产日韩91久久久久久 | 国产精品www | 精品三级在线观看 | 一区二区三区免费 | 99精品网站 | 国产精品一区二 | 啪啪综合网| 免费在线看a |