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

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

  • <tfoot id='mgqWs'></tfoot>
    <legend id='mgqWs'><style id='mgqWs'><dir id='mgqWs'><q id='mgqWs'></q></dir></style></legend>

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

        Python多處理池在加入時掛起?

        Python multiprocessing pool hangs at join?(Python多處理池在加入時掛起?)

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

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

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

              • <bdo id='mbyPH'></bdo><ul id='mbyPH'></ul>
                  <tbody id='mbyPH'></tbody>
                  本文介紹了Python多處理池在加入時掛起?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我正在嘗試在多個文件上并行運行一些 python 代碼.構造基本上是:

                  I'm trying to run some python code on several files in parallel. The construct is basically:

                  def process_file(filename, foo, bar, baz=biz):
                      # do stuff that may fail and cause exception
                  
                  if __name__ == '__main__':
                      # setup code setting parameters foo, bar, and biz
                  
                      psize = multiprocessing.cpu_count()*2
                      pool = multiprocessing.Pool(processes=psize)
                  
                      map(lambda x: pool.apply_async(process_file, (x, foo, bar), dict(baz=biz)), sys.argv[1:])
                      pool.close()
                      pool.join()
                  

                  我以前使用 pool.map 來做類似的事情并且效果很好,但我似乎不能在這里使用它,因為 pool.map 不允許(似乎)允許我傳遞額外的參數(并且使用 lambda 來做這件事是行不通的,因為 lambda 不能被編組).

                  I've previously used pool.map to do something similar and it worked great, but I can't seem to use that here because pool.map doesn't (appear to) allow me to pass in extra arguments (and using lambda to do it won't work because lambda can't be marshalled).

                  所以現在我正在嘗試直接使用 apply_async() 來讓事情正常工作.我的問題是代碼似乎掛起并且永遠不會退出.一些文件因異常而失敗,但我不明白為什么會導致連接失敗/掛起?有趣的是,如果沒有一個文件因異常而失敗,它確實會干凈地退出.

                  So now I'm trying to get things to work using apply_async() directly. My issue is that the code seems to hang and never exit. A few of the files fail with an exception, but i don't see why what would cause join to fail/hang? Interestingly if none of the files fail with an exception, it does exit cleanly.

                  我錯過了什么?

                  當函數(以及工作程序)失敗時,我看到了這個異常:

                  When the function (and thus a worker) fails, I see this exception:

                  Exception in thread Thread-3:
                  Traceback (most recent call last):
                    File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
                      self.run()
                    File "/usr/lib/python2.7/threading.py", line 505, in run
                      self.__target(*self.__args, **self.__kwargs)
                    File "/usr/lib/python2.7/multiprocessing/pool.py", line 376, in _handle_results
                      task = get()
                  TypeError: ('__init__() takes at least 3 arguments (1 given)', <class 'subprocess.CalledProcessError'>, ())
                  

                  如果我看到其中之一,進程父進程將永遠掛起,永遠不會收獲子進程并退出.

                  If i see even one of these, the process parent process hangs forever, never reaping the children and exiting.

                  推薦答案

                  很抱歉回答我自己的問題,但我至少找到了一種解決方法,所以如果其他人有類似的問題,我想在這里發布.我會接受任何更好的答案.

                  Sorry to answer my own question, but I've found at least a workaround so in case anyone else has a similar issue I want to post it here. I'll accept any better answers out there.

                  我認為問題的根源是 http://bugs.python.org/issue9400 .這告訴我兩件事:

                  I believe the root of the issue is http://bugs.python.org/issue9400 . This tells me two things:

                  • 我沒瘋,我正在努力做的事情真的應該奏效
                  • 至少在 python2 中,如果不是不可能的話,將異常"返回到父進程是非常困難的.簡單的方法有效,但許多其他方法無效.

                  就我而言,我的工作函數正在啟動一個存在段錯誤的子進程.這返回了 CalledProcessError 異常,這是不可腌制的.出于某種原因,這使得父對象中的池對象出去吃午飯,而不是從對 join() 的調用中返回.

                  In my case, my worker function was launching a subprocess that was segfaulting. This returned CalledProcessError exception, which is not pickleable. For some reason, this makes the pool object in the parent go out to lunch and not return from the call to join().

                  在我的特殊情況下,我不在乎異常是什么.最多我想記錄它并繼續前進.為此,我只需將我的頂級工作函數包裝在 try/except 子句中.如果工作進程拋出任何異常,它會在嘗試返回父進程之前被捕獲,記錄,然后工作進程正常退出,因為它不再嘗試發送異常.見下文:

                  In my particular case, I don't care what the exception was. At most I want to log it and keep going. To do this, I simply wrap my top worker function in a try/except clause. If the worker throws any exception, it is caught before trying to return to the parent process, logged, and then the worker process exits normally since it's no longer trying to send the exception through. See below:

                  def process_file_wrapped(filenamen, foo, bar, baz=biz):
                      try:
                          process_file(filename, foo, bar, baz=biz)
                      except:
                          print('%s: %s' % (filename, traceback.format_exc()))
                  

                  然后,我有我的初始映射函數調用 process_file_wrapped() 而不是原來的.現在我的代碼按預期工作.

                  Then, I have my initial map function call process_file_wrapped() instead of the original one. Now my code works as intended.

                  這篇關于Python多處理池在加入時掛起?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多處理模塊的 .join() 方法到底在做什么?)
                  Passing multiple parameters to pool.map() function in Python(在 Python 中將多個參數傳遞給 pool.map() 函數)
                  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 多進程池.當其中一個工作進程確定不再需要完成工作時,如何退出腳本?) - IT屋-程序員
                  How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊列引用傳遞給 pool.map_async() 管理的函數?)
                  yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯誤的另一個混淆,“模塊對象沒有屬性“f)
                  <legend id='060xw'><style id='060xw'><dir id='060xw'><q id='060xw'></q></dir></style></legend>

                  • <tfoot id='060xw'></tfoot>

                        1. <i id='060xw'><tr id='060xw'><dt id='060xw'><q id='060xw'><span id='060xw'><b id='060xw'><form id='060xw'><ins id='060xw'></ins><ul id='060xw'></ul><sub id='060xw'></sub></form><legend id='060xw'></legend><bdo id='060xw'><pre id='060xw'><center id='060xw'></center></pre></bdo></b><th id='060xw'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='060xw'><tfoot id='060xw'></tfoot><dl id='060xw'><fieldset id='060xw'></fieldset></dl></div>
                            <bdo id='060xw'></bdo><ul id='060xw'></ul>
                              <tbody id='060xw'></tbody>
                          • <small id='060xw'></small><noframes id='060xw'>

                            主站蜘蛛池模板: 日韩三级电影在线看 | 91精品亚洲 | 久久99精品久久久久久国产越南 | 亚州中文| 日韩精品视频在线免费观看 | 欧美日韩精品免费观看 | 久热国产在线 | 精品一区二区久久久久久久网站 | av中文字幕在线播放 | 日本久草视频 | 自拍视频在线观看 | 久久一二 | 国产日韩欧美另类 | 午夜小电影 | 91精品国产乱码久久久久久久 | 欧美一级视频免费看 | 日日日操 | 深夜爽视频 | h视频网站在线观看 | 中文字幕综合 | 亚洲色欲色欲www | 国产中文视频 | 久久久久一区 | 午夜黄色影院 | 久久er99热精品一区二区 | 日韩日b视频| 国产精品久久久久久中文字 | 欧美一级高潮片免费的 | 亚洲成人一区二区 | 日韩高清在线 | 欧洲成人免费视频 | 在线观看精品 | 偷拍自拍在线观看 | 日日操夜夜操天天操 | 日韩国产在线 | 成人精品一区二区 | 日韩免费视频 | 亚洲一区二区三区免费观看 | 欧美日本韩国一区二区三区 | 精品国产91乱码一区二区三区 | 91精品国产综合久久婷婷香蕉 |