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

  • <tfoot id='nNLfV'></tfoot>

    1. <small id='nNLfV'></small><noframes id='nNLfV'>

          <bdo id='nNLfV'></bdo><ul id='nNLfV'></ul>

        <i id='nNLfV'><tr id='nNLfV'><dt id='nNLfV'><q id='nNLfV'><span id='nNLfV'><b id='nNLfV'><form id='nNLfV'><ins id='nNLfV'></ins><ul id='nNLfV'></ul><sub id='nNLfV'></sub></form><legend id='nNLfV'></legend><bdo id='nNLfV'><pre id='nNLfV'><center id='nNLfV'></center></pre></bdo></b><th id='nNLfV'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='nNLfV'><tfoot id='nNLfV'></tfoot><dl id='nNLfV'><fieldset id='nNLfV'></fieldset></dl></div>
        <legend id='nNLfV'><style id='nNLfV'><dir id='nNLfV'><q id='nNLfV'></q></dir></style></legend>
      1. Python 多處理 &gt;= 125 列表永遠不會完成

        Python multiprocessing gt;= 125 list never finishes(Python 多處理 gt;= 125 列表永遠不會完成)

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

                <tbody id='dgLaX'></tbody>
            • <small id='dgLaX'></small><noframes id='dgLaX'>

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

                <tfoot id='dgLaX'></tfoot>
                  本文介紹了Python 多處理 &gt;= 125 列表永遠不會完成的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試實現這個多處理 教程 用于我自己的目的.起初我認為它不能很好地擴展,但是當我做了一個可重現的例子時,我發現如果項目列表超過 124,它似乎永遠不會返回答案.在 x = 124 處,它在 0.4 秒內運行,但是當我將其設置為 x = 125 時,它永遠不會完成.我在 Windows 7 上運行 Python 2.7.

                  I am trying to implement this multiprocessing tutorial for my own purposes. At first I thought it did not scale well, but when I made a reproducible example I found that if the list of items goes above 124, it seems to never return an answer. At x = 124 it runs in .4 seconds, but when I set it to x = 125 it never finishes. I am running Python 2.7 on Windows 7.

                  from multiprocessing import Lock, Process, Queue, current_process
                  import time
                  
                  class Testclass(object):
                      def __init__(self, x):
                          self.x = x
                  
                  def toyfunction(testclass):
                      testclass.product = testclass.x * testclass.x
                      return testclass
                  
                  
                  def worker(work_queue, done_queue):
                      try:
                          for testclass in iter(work_queue.get, 'STOP'):
                              print(testclass.counter)
                              newtestclass = toyfunction(testclass)
                              done_queue.put(newtestclass)
                  
                      except:
                          print('error')
                  
                      return True
                  
                  def main(x):
                  
                      counter = 1
                  
                      database = []
                      while counter <= x:
                          database.append(Testclass(10))
                          counter += 1
                          print(counter)
                  
                  
                  
                      workers = 8
                      work_queue = Queue()
                      done_queue = Queue()
                      processes = []
                  
                      start = time.clock()
                      counter = 1
                  
                      for testclass in database:
                          testclass.counter = counter
                          work_queue.put(testclass)
                          counter += 1
                          print(counter)
                  
                  
                      print('items loaded')
                      for w in range(workers):
                          p = Process(target=worker, args=(work_queue, done_queue))
                          p.start()
                          processes.append(p)
                          work_queue.put('STOP')
                  
                      for p in processes:
                          p.join()
                  
                      done_queue.put('STOP')
                  
                      newdatabase = []
                      for testclass in iter(done_queue.get, 'STOP'):
                          newdatabase.append(testclass)
                  
                      print(time.clock()-start)
                      print("Done")
                      return(newdatabase)
                  
                  if __name__ == '__main__':
                      database = main(124)
                      database2 = main(125)
                  

                  推薦答案

                  好的!來自文檔:

                  警告如上所述,如果子進程已將項目放入隊列中(并且它沒有使用 JoinableQueue.cancel_join_thread),那么該進程將不會終止,直到所有緩沖的項目已被刷新到管道.這意味著如果您嘗試加入該進程,除非您確定,否則您可能會遇到死鎖已放入隊列的所有項目都已被消耗.同樣,如果子進程是非守護進程,然后父進程可能會在嘗試退出時掛起加入其所有非惡魔的孩子.請注意,使用管理器創建的隊列確實沒有這個問題.請參閱編程指南.

                  Warning As mentioned above, if a child process has put items on a queue (and it has not used JoinableQueue.cancel_join_thread), then that process will not terminate until all buffered items have been flushed to the pipe. This means that if you try joining that process you may get a deadlock unless you are sure that all items which have been put on the queue have been consumed. Similarly, if the child process is non-daemonic then the parent process may hang on exit when it tries to join all its non-daemonic children. Note that a queue created using a manager does not have this issue. See Programming guidelines.

                  正如我在前面的評論中指出的,代碼嘗試 .join() 處理 before done_queue 隊列耗盡 - 并且在以一種時髦的方式更改代碼以確保在 .join() 之前耗盡了 done_queue 之后,代碼對一百萬個項目運行良好.

                  As I noted in a comment earlier, the code attempts to .join() processes before the done_queue Queue is drained - and that after changing the code in a funky way to be sure done_queue was drained before .join()'ing, the code worked fine for a million items.

                  所以這是一個飛行員錯誤的例子,雖然很模糊.至于為什么行為取決于傳遞給 main(x) 的數字,這是不可預測的:它取決于內部緩沖是如何完成的.真有趣;-)

                  So this is a case of pilot error, although quite obscure. As to why behavior depends on the number passed to main(x), it's unpredictable: it depends on how buffering is done internally. Such fun ;-)

                  這篇關于Python 多處理 &gt;= 125 列表永遠不會完成的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構造函數有未知關鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)
                1. <i id='d1EGH'><tr id='d1EGH'><dt id='d1EGH'><q id='d1EGH'><span id='d1EGH'><b id='d1EGH'><form id='d1EGH'><ins id='d1EGH'></ins><ul id='d1EGH'></ul><sub id='d1EGH'></sub></form><legend id='d1EGH'></legend><bdo id='d1EGH'><pre id='d1EGH'><center id='d1EGH'></center></pre></bdo></b><th id='d1EGH'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='d1EGH'><tfoot id='d1EGH'></tfoot><dl id='d1EGH'><fieldset id='d1EGH'></fieldset></dl></div>
                2. <tfoot id='d1EGH'></tfoot>
                    <bdo id='d1EGH'></bdo><ul id='d1EGH'></ul>

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

                            <legend id='d1EGH'><style id='d1EGH'><dir id='d1EGH'><q id='d1EGH'></q></dir></style></legend>
                              <tbody id='d1EGH'></tbody>
                          • 主站蜘蛛池模板: 国产福利资源在线 | 久久国产精99精产国高潮 | 国产精品明星裸体写真集 | 免费成人在线网站 | 亚洲精品国产成人 | 黄色一级大片在线免费看产 | 国产精品3区 | 一级毛片视频免费观看 | 久久久综合色 | 亚洲精品久久久久久一区二区 | 欧美一级片在线 | 欧美成人免费在线视频 | 激情毛片 | 国产欧美精品区一区二区三区 | 久热电影 | 蜜臀久久 | 一区二区精品 | 国产精品精品视频一区二区三区 | 日韩有码在线观看 | 欧美成人黄色小说 | 亚洲精品成人网 | 在线播放一区二区三区 | 日韩免费1区二区电影 | 欧美视频一区二区三区 | 国内自拍偷拍 | 2021狠狠干 | 日本三级网站在线 | 久久久久久美女 | 九九热国产视频 | 亚洲精品日韩综合观看成人91 | 国产精品一区二区久久 | 视频一区二区在线观看 | 久久久爽爽爽美女图片 | 亚洲国产成人精品女人久久久 | 免费成人午夜 | 亚洲码欧美码一区二区三区 | 黄色一级免费观看 | 亚洲精品中文字幕 | 一区二区三区四区在线 | 99久久婷婷国产综合精品电影 | 免费国产精品久久久久久 |