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

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

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

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

        python multiprocessing apply_async 只使用一個(gè)進(jìn)程

        python multiprocessing apply_async only uses one process(python multiprocessing apply_async 只使用一個(gè)進(jìn)程)
      1. <legend id='MPGwf'><style id='MPGwf'><dir id='MPGwf'><q id='MPGwf'></q></dir></style></legend>
      2. <i id='MPGwf'><tr id='MPGwf'><dt id='MPGwf'><q id='MPGwf'><span id='MPGwf'><b id='MPGwf'><form id='MPGwf'><ins id='MPGwf'></ins><ul id='MPGwf'></ul><sub id='MPGwf'></sub></form><legend id='MPGwf'></legend><bdo id='MPGwf'><pre id='MPGwf'><center id='MPGwf'></center></pre></bdo></b><th id='MPGwf'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='MPGwf'><tfoot id='MPGwf'></tfoot><dl id='MPGwf'><fieldset id='MPGwf'></fieldset></dl></div>
          <bdo id='MPGwf'></bdo><ul id='MPGwf'></ul>

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

                1. <tfoot id='MPGwf'></tfoot>
                    <tbody id='MPGwf'></tbody>
                2. 本文介紹了python multiprocessing apply_async 只使用一個(gè)進(jìn)程的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  限時(shí)送ChatGPT賬號(hào)..

                  我有一個(gè)腳本,其中包括從列表中打開(kāi)一個(gè)文件,然后對(duì)該文件中的文本執(zhí)行某些操作.我正在使用 python 多處理和 Pool 來(lái)嘗試并行化此操作.腳本的抽象如下:

                  I have a script that includes opening a file from a list and then doing something to the text within that file. I'm using python multiprocessing and Pool to try to parallelize this operation. A abstraction of the script is below:

                  import os
                  from multiprocessing import Pool
                  
                  results = []
                  def testFunc(files):
                      for file in files:
                          print "Working in Process #%d" % (os.getpid())
                          #This is just an illustration of some logic. This is not what I'm actually doing.
                          for line in file:
                              if 'dog' in line:
                                  results.append(line)
                  
                  if __name__=="__main__":
                      p = Pool(processes=2)
                      files = ['/path/to/file1.txt', '/path/to/file2.txt']
                      results = p.apply_async(testFunc, args = (files,))
                      results2 = results.get()
                  

                  當(dāng)我運(yùn)行此程序時(shí),每次迭代的進(jìn)程 ID 打印輸出都是相同的.基本上我要做的是獲取輸入列表的每個(gè)元素并將其分叉到一個(gè)單獨(dú)的進(jìn)程中,但似乎一個(gè)進(jìn)程正在完成所有工作.

                  When I run this the print out of the process id is the same for each iteration. Basically what I'm trying to do is take each element of the input list and fork it out to a separate process, but it seems like one process is doing all of the work.

                  推薦答案

                  • apply_async 將一項(xiàng)任務(wù)分配給池.你需要打電話apply_async 多次以鍛煉更多處理器.
                  • 不要讓兩個(gè)進(jìn)程都嘗試寫(xiě)入同一個(gè)列表,結(jié)果.由于池工作者是獨(dú)立的進(jìn)程,這兩個(gè)不會(huì)寫(xiě)入同一個(gè)列表.解決此問(wèn)題的一種方法是使用輸出隊(duì)列.您可以自己設(shè)置,或使用 apply_async 的回調(diào)為您設(shè)置隊(duì)列.apply_async 將在函數(shù)完成后調(diào)用回調(diào).
                  • 你可以使用 map_async 代替 apply_async,但是你會(huì)獲取列表列表,然后您必須將其展平.
                    • apply_async farms out one task to the pool. You would need to call apply_async many times to exercise more processors.
                    • Don't allow both processes to try to write to the same list, results. Since the pool workers are separate processes, the two won't be writing to the same list. One way to work around this is to use an ouput Queue. You could set it up yourself, or use apply_async's callback to setup the Queue for you. apply_async will call the callback once the function completes.
                    • You could use map_async instead of apply_async, but then you'd get a list of lists, which you'd then have to flatten.
                    • 所以,不妨試試類似的方法:

                      So, perhaps try instead something like:

                      import os
                      import multiprocessing as mp
                      
                      results = []   
                      
                      def testFunc(file):
                          result = []
                          print "Working in Process #%d" % (os.getpid())
                          # This is just an illustration of some logic. This is not what I'm
                          # actually doing.
                          with open(file, 'r') as f:
                              for line in f:
                                  if 'dog' in line:
                                      result.append(line)
                          return result
                      
                      
                      def collect_results(result):
                          results.extend(result)
                      
                      if __name__ == "__main__":
                          p = mp.Pool(processes=2)
                          files = ['/path/to/file1.txt', '/path/to/file2.txt']
                          for f in files:
                              p.apply_async(testFunc, args=(f, ), callback=collect_results)
                          p.close()
                          p.join()
                          print(results)
                      

                      這篇關(guān)于python multiprocessing apply_async 只使用一個(gè)進(jìn)程的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                      【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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 中將多個(gè)參數(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屋-程序員軟件開(kāi)
                  Python Multiprocess Pool. How to exit the script when one of the worker process determines no more work needs to be done?(Python 多進(jìn)程池.當(dāng)其中一個(gè)工作進(jìn)程確定不再需要完成工作時(shí),如何退出腳本?) - IT屋-程序員
                  How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊(duì)列引用傳遞給 pool.map_async() 管理的函數(shù)?)
                  yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯(cuò)誤的另一個(gè)混淆,“模塊對(duì)象沒(méi)有屬性“f)
                    <tbody id='JUbbv'></tbody>
                    <bdo id='JUbbv'></bdo><ul id='JUbbv'></ul>

                      <legend id='JUbbv'><style id='JUbbv'><dir id='JUbbv'><q id='JUbbv'></q></dir></style></legend><tfoot id='JUbbv'></tfoot>

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

                          • <small id='JUbbv'></small><noframes id='JUbbv'>

                            主站蜘蛛池模板: 久久天天 | 97国产精品视频人人做人人爱 | 一区2区| 国产视频1 | 99视频免费在线观看 | 在线欧美小视频 | 国产精品一区二区av | 中文字幕成人av | 欧美一区二区在线 | 91精品国产91综合久久蜜臀 | 操操操操操 | 色男人的天堂 | 日日射夜夜骑 | 久久精品欧美一区二区三区不卡 | 国产一级在线 | 亚洲综合色视频在线观看 | 国产精品久久久久久久岛一牛影视 | 欧美在线视频二区 | 91动漫在线观看 | 成人午夜精品 | 国产日韩精品视频 | 亚洲视频免费 | 午夜视频在线免费观看 | 91偷拍精品一区二区三区 | 国产一区精品 | 亚洲国产欧美国产综合一区 | 午夜在线精品偷拍 | 久久中文字幕一区 | 久久福利电影 | hitomi一区二区三区精品 | 国产亚洲网站 | 69av片| 久久久婷婷 | 国产91在线 | 亚洲 | 久久精品视频9 | 成人在线视频免费观看 | 成人免费小视频 | 91精品91久久久 | 青青草这里只有精品 | 欧美精品在欧美一区二区 | 国产精品久久久久久久久久久久久久 |