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

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

      <legend id='Zj6xR'><style id='Zj6xR'><dir id='Zj6xR'><q id='Zj6xR'></q></dir></style></legend>
        <bdo id='Zj6xR'></bdo><ul id='Zj6xR'></ul>
      <tfoot id='Zj6xR'></tfoot>
    1. <small id='Zj6xR'></small><noframes id='Zj6xR'>

      1. Python:在使用多處理池時使用隊列寫入單個文件

        Python: Writing to a single file with queue while using multiprocessing Pool(Python:在使用多處理池時使用隊列寫入單個文件)
            <tbody id='bcHsj'></tbody>

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

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

                <tfoot id='bcHsj'></tfoot>
                • <bdo id='bcHsj'></bdo><ul id='bcHsj'></ul>
                  本文介紹了Python:在使用多處理池時使用隊列寫入單個文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我有數(shù)十萬個文本文件,我想以各種方式進(jìn)行解析.我想將輸出保存到單個文件而不會出現(xiàn)同步問題.我一直在使用多處理池來執(zhí)行此操作以節(jié)省時間,但我不知道如何組合池和隊列.

                  I have hundreds of thousands of text files that I want to parse in various ways. I want to save the output to a single file without synchronization problems. I have been using multiprocessing pool to do this to save time, but I can't figure out how to combine Pool and Queue.

                  以下代碼將保存文件名以及文件中連續(xù)x"的最大數(shù)量.但是,我希望所有進(jìn)程都將結(jié)果保存到同一個文件中,而不是像我的示例中那樣保存到不同的文件中.對此的任何幫助將不勝感激.

                  The following code will save the infile name as well as the maximum number of consecutive "x"s in the file. However, I want all processes to save results to the same file, and not to different files as in my example. Any help on this would be greatly appreciated.

                  import multiprocessing
                  
                  with open('infilenamess.txt') as f:
                      filenames = f.read().splitlines()
                  
                  def mp_worker(filename):
                   with open(filename, 'r') as f:
                        text=f.read()
                        m=re.findall("x+", text)
                        count=len(max(m, key=len))
                        outfile=open(filename+'_results.txt', 'a')
                        outfile.write(str(filename)+'|'+str(count)+'
                  ')
                        outfile.close()
                  
                  def mp_handler():
                      p = multiprocessing.Pool(32)
                      p.map(mp_worker, filenames)
                  
                  if __name__ == '__main__':
                      mp_handler()
                  

                  推薦答案

                  多處理池為您實現(xiàn)了一個隊列.只需使用將工作人員返回值返回給調(diào)用者的池方法.imap 運行良好:

                  Multiprocessing pools implement a queue for you. Just use a pool method that returns the worker return value to the caller. imap works well:

                  import multiprocessing 
                  import re
                  
                  def mp_worker(filename):
                      with open(filename) as f:
                          text = f.read()
                      m = re.findall("x+", text)
                      count = len(max(m, key=len))
                      return filename, count
                  
                  def mp_handler():
                      p = multiprocessing.Pool(32)
                      with open('infilenamess.txt') as f:
                          filenames = [line for line in (l.strip() for l in f) if line]
                      with open('results.txt', 'w') as f:
                          for result in p.imap(mp_worker, filenames):
                              # (filename, count) tuples from worker
                              f.write('%s: %d
                  ' % result)
                  
                  if __name__=='__main__':
                      mp_handler()
                  

                  這篇關(guān)于Python:在使用多處理池時使用隊列寫入單個文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 多進(jìn)程池.當(dāng)其中一個工作進(jìn)程確定不再需要完成工作時,如何退出腳本?) - 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)

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

                        <legend id='zenZt'><style id='zenZt'><dir id='zenZt'><q id='zenZt'></q></dir></style></legend>
                          <tbody id='zenZt'></tbody>
                          • <small id='zenZt'></small><noframes id='zenZt'>

                          • 主站蜘蛛池模板: 亚洲+变态+欧美+另类+精品 | 亚洲精品乱码 | 在线看免费| 日韩免费福利视频 | 国产一区亚洲二区三区 | 国产精品18久久久久久白浆动漫 | 成人h视频| 人人澡人人射 | 成人性生交大片免费看中文带字幕 | 欧美日韩国产中文 | 亚洲一区二区三区四区五区午夜 | 天堂中文在线观看 | 亚洲欧美中文日韩在线v日本 | 男女羞羞视频在线看 | 亚洲欧美激情网 | 精品久久久久一区二区国产 | 亚洲欧美aⅴ | 91偷拍精品一区二区三区 | 日韩在线一区二区三区 | 久久久成人一区二区免费影院 | 国产精品成人一区二区三区 | 欧美成人一级 | 国产精品一区二区三区在线 | 亚洲精品日韩在线观看 | 免费精品| 国产一区二区三区久久久久久久久 | 国产欧美一区二区三区在线看 | 日本激情视频在线播放 | 2018中文字幕第一页 | 在线免费观看黄色 | 成人在线一区二区 | 国产一区二区三区在线观看免费 | 欧美精品一区二区三区蜜臀 | 一区二区三区在线播放 | 亚洲 欧美 在线 一区 | 91一区二区三区 | 欧美精品tv| 天天天操操操 | 日韩看片 | 国产视频1 | 男女羞羞的网站 |