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

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

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

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

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

      1. 如何使用 Python 多處理池處理 tarfile?

        How can I process a tarfile with a Python multiprocessing pool?(如何使用 Python 多處理池處理 tarfile?)

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

            <tbody id='2pLJz'></tbody>
          • <small id='2pLJz'></small><noframes id='2pLJz'>

              <bdo id='2pLJz'></bdo><ul id='2pLJz'></ul>
                  <legend id='2pLJz'><style id='2pLJz'><dir id='2pLJz'><q id='2pLJz'></q></dir></style></legend>
                  本文介紹了如何使用 Python 多處理池處理 tarfile?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在嘗試使用 multiprocessing.Pool 處理 tar 文件的內(nèi)容.我能夠在多處理模塊中成功使用 ThreadPool 實(shí)現(xiàn),但希望能夠使用進(jìn)程而不是線程,因?yàn)樗赡軙?huì)更快并消除為 Matplotlib 處理多線程環(huán)境所做的一些更改.我收到一個(gè)錯(cuò)誤,我懷疑與進(jìn)程不共享地址空間有關(guān),但我不確定如何修復(fù)它:

                  I'm trying to process the contents of a tarfile using multiprocessing.Pool. I'm able to successfully use the ThreadPool implementation within the multiprocessing module, but would like to be able to use processes instead of threads as it would possibly be faster and eliminate some changes made for Matplotlib to handle the multithreaded environment. I'm getting an error that I suspect is related to processes not sharing address space, but I'm not sure how to fix it:

                  Traceback (most recent call last):
                    File "test_tarfile.py", line 32, in <module>
                      test_multiproc()
                    File "test_tarfile.py", line 24, in test_multiproc
                      pool.map(read_file, files)
                    File "/ldata/whitcomb/epd-7.1-2-rh5-x86_64/lib/python2.7/multiprocessing/pool.py", line 225, in map
                      return self.map_async(func, iterable, chunksize).get()
                    File "/ldata/whitcomb/epd-7.1-2-rh5-x86_64/lib/python2.7/multiprocessing/pool.py", line 522, in get
                      raise self._value
                  ValueError: I/O operation on closed file
                  

                  實(shí)際的程序更復(fù)雜,但這是我正在做的一個(gè)重現(xiàn)錯(cuò)誤的示例:

                  The actual program is more complicated, but this is an example of what I'm doing that reproduces the error:

                  from multiprocessing.pool import ThreadPool, Pool
                  import StringIO
                  import tarfile
                  
                  def write_tar():
                      tar = tarfile.open('test.tar', 'w')
                      contents = 'line1'
                      info = tarfile.TarInfo('file1.txt')
                      info.size = len(contents)
                      tar.addfile(info, StringIO.StringIO(contents))
                      tar.close()
                  
                  def test_multithread():
                      tar   = tarfile.open('test.tar')
                      files = [tar.extractfile(member) for member in tar.getmembers()]
                      pool  = ThreadPool(processes=1)
                      pool.map(read_file, files)
                      tar.close()
                  
                  def test_multiproc():
                      tar   = tarfile.open('test.tar')
                      files = [tar.extractfile(member) for member in tar.getmembers()]
                      pool  = Pool(processes=1)
                      pool.map(read_file, files)
                      tar.close()
                  
                  def read_file(f):
                      print f.read()
                  
                  write_tar()
                  test_multithread()
                  test_multiproc()
                  

                  我懷疑當(dāng) TarInfo 對(duì)象被傳遞到另一個(gè)進(jìn)程但父 TarFile 不是時(shí)出現(xiàn)問題,但我不確定如何修復(fù)它在多進(jìn)程情況下.我可以在不必從 tarball 中提取文件并將它們寫入磁盤的情況下執(zhí)行此操作嗎?

                  I suspect that the something's wrong when the TarInfo object is passed into the other process but the parent TarFile is not, but I'm not sure how to fix it in the multiprocess case. Can I do this without having to extract files from the tarball and write them to disk?

                  推薦答案

                  您沒有將 TarInfo 對(duì)象傳遞給其他進(jìn)程,而是將 tar.extractfile 的結(jié)果傳遞給其他進(jìn)程(member) 進(jìn)入另一個(gè)進(jìn)程,其中 member 是一個(gè) TarInfo 對(duì)象.extractfile(...) 方法返回一個(gè)類似文件的對(duì)象,其中包括一個(gè) read() 方法,該方法對(duì)您打開的原始 tar 文件進(jìn)行操作tar = tarfile.open('test.tar').

                  You're not passing a TarInfo object into the other process, you're passing the result of tar.extractfile(member) into the other process where member is a TarInfo object. The extractfile(...) method returns a file-like object which has, among other things, a read() method which operates upon the original tar file you opened with tar = tarfile.open('test.tar').

                  但是,您不能在另一個(gè)進(jìn)程中使用來自一個(gè)進(jìn)程的打開文件,您必須重新打開該文件.我用這個(gè)替換了你的 test_multiproc():

                  However, you can't use an open file from one process in another process, you have to re-open the file. I replaced your test_multiproc() with this:

                  def test_multiproc():
                      tar   = tarfile.open('test.tar')
                      files = [name for name in tar.getnames()]
                      pool  = Pool(processes=1)
                      result = pool.map(read_file2, files)
                      tar.close()
                  

                  并添加了這個(gè):

                  def read_file2(name):
                      t2 = tarfile.open('test.tar')
                      print t2.extractfile(name).read()
                      t2.close()
                  

                  并且能夠讓您的代碼正常工作.

                  and was able to get your code working.

                  這篇關(guān)于如何使用 Python 多處理池處理 tarfile?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動(dòng)后進(jìn)度躍升至 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 刻度標(biāo)簽設(shè)置在固定位置,以便當(dāng)我向左或向右滾動(dòng)時(shí),yaxis 刻度標(biāo)簽應(yīng)該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構(gòu)造函數(shù)有未知關(guān)鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時(shí)顯示進(jìn)度條?)

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

                        1. <small id='8RoQi'></small><noframes id='8RoQi'>

                            主站蜘蛛池模板: 影音先锋中文在线 | 婷婷色在线 | 久久国产精品久久久久 | 国产精品久久国产愉拍 | 国产乱码久久久久久 | 欧美一级片免费看 | 国产精品国产成人国产三级 | 青青草视频免费观看 | 国产精品成人一区二区三区吃奶 | 欧美中文字幕一区二区三区亚洲 | 欧美 日韩 国产 一区 | 成人做爰www免费看 午夜精品久久久久久久久久久久 | 99精品亚洲国产精品久久不卡 | 欧美精品1区2区 | 永久免费视频 | 国产精品欧美一区喷水 | 日韩av一区在线观看 | 国产精品一区二区福利视频 | 久久国产秒 | 国产精品视频www | 在线观看av中文字幕 | 理论片免费在线观看 | 欧美日韩国产免费 | 欧美日高清| 国产精品日韩欧美一区二区 | 国产电影一区二区三区爱妃记 | 精品日韩在线 | 欧美精品一区二区三区在线 | 亚洲成人av| 国产成人精品一区二区三区四区 | 在线观看精品 | 久久免费视频1 | 完全免费在线视频 | 成人夜晚看av | 国产一区欧美 | 91在线视频| 国产欧美一区二区三区免费 | 国产一区久久 | 国产美女精品视频免费观看 | 精品一区二区三区在线观看国产 | 黄色片在线观看网址 |