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

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

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

      • <bdo id='Z4WFF'></bdo><ul id='Z4WFF'></ul>

      multiprocessing.pool.MaybeEncodingError: 'TypeError("

      multiprocessing.pool.MaybeEncodingError: #39;TypeError(quot;cannot serialize #39;_io.BufferedReader#39; objectquot;,)#39;(multiprocessing.pool.MaybeEncodingError: TypeError(cannot serialize _io.BufferedReader object,)) - IT屋-程序員軟件開
          <tbody id='E39k9'></tbody>

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

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

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

                本文介紹了multiprocessing.pool.MaybeEncodingError: 'TypeError("cannot serialize '_io.BufferedReader' object",)'的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                為什么下面的代碼只適用于multiprocessing.dummy,而不適用于簡單的multiprocessing.

                Why does the code below work only with multiprocessing.dummy, but not with simple multiprocessing.

                import urllib.request
                #from multiprocessing.dummy import Pool #this works
                from multiprocessing import Pool
                
                urls = ['http://www.python.org', 'http://www.yahoo.com','http://www.scala.org', 'http://www.google.com']
                
                if __name__ == '__main__':
                    with Pool(5) as p:
                        results = p.map(urllib.request.urlopen, urls)
                

                錯誤:

                Traceback (most recent call last):
                  File "urlthreads.py", line 31, in <module>
                    results = p.map(urllib.request.urlopen, urls)
                  File "C:UserspatriAnaconda3libmultiprocessingpool.py", line 268, in map
                    return self._map_async(func, iterable, mapstar, chunksize).get()
                  File "C:UserspatriAnaconda3libmultiprocessingpool.py", line 657, in get
                    raise self._value
                multiprocessing.pool.MaybeEncodingError: Error sending result: '[<http.client.HTTPResponse object at 0x0000016AEF204198>]'. Reason: 'TypeError("cannot serialize '_io.BufferedReader' object")'
                

                缺少什么才能在沒有虛擬"的情況下工作?

                What's missing so that it works without "dummy" ?

                推薦答案

                你從 urlopen() 得到的 http.client.HTTPResponse-object 有一個 >_io.BufferedReader - 附加對象,這個對象不能被pickle.

                The http.client.HTTPResponse-object you get back from urlopen() has a _io.BufferedReader-object attached, and this object cannot be pickled.

                pickle.dumps(urllib.request.urlopen('http://www.python.org').fp)
                Traceback (most recent call last):
                ...
                    pickle.dumps(urllib.request.urlopen('http://www.python.org').fp)
                TypeError: cannot serialize '_io.BufferedReader' object
                

                multiprocessing.Pool 將需要腌制(序列化)結果以將其發送回父進程,但此處失敗.由于 dummy 使用線程而不是進程,因此不會出現酸洗,因為同一進程中的線程自然共享它們的內存.

                multiprocessing.Pool will need to pickle (serialize) the results to send it back to the parent process and this fails here. Since dummy uses threads instead of processes, there will be no pickling, because threads in the same process share their memory naturally.

                這個TypeError的一般解決方案是:

                A general solution to this TypeError is:

                1. 讀出緩沖區并保存內容(如果需要)
                2. 從您嘗試腌制的對象中刪除對 '_io.BufferedReader' 的引用

                在您的情況下,在 http.client.HTTPResponse 上調用 .read() 將清空并刪除緩沖區,因此是用于將響應轉換為可腌制內容的函數可以這樣做:

                In your case, calling .read() on the http.client.HTTPResponse will empty and remove the buffer, so a function for converting the response into something pickleable could simply do this:

                def read_buffer(response):
                    response.text = response.read()
                    return response
                

                例子:

                r = urllib.request.urlopen('http://www.python.org')
                r = read_buffer(r)
                pickle.dumps(r)
                # Out: b'x80x03chttp.client
                HTTPResponse...
                

                在考慮這種方法之前,請確保您確實想要使用多處理而不是多線程.對于像您在此處擁有的 I/O 綁定任務,多線程就足夠了,因為無論如何大部分時間都花在等待響應上(不需要 cpu 時間).多處理和所涉及的 IPC 也會帶來大量開銷.

                Before you consider this approach, make sure you really want to use multiprocessing instead of multithreading. For I/O-bound tasks like you have it here, multithreading would be sufficient, since most of the time is spend in waiting (no need for cpu-time) for the response anyway. Multiprocessing and the IPC involved also introduces substantial overhead.

                這篇關于multiprocessing.pool.MaybeEncodingError: 'TypeError("cannot serialize '_io.BufferedReader' object",)'的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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() 函數)
                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)
                Multiprocessing : use tqdm to display a progress bar(多處理:使用 tqdm 顯示進度條)
                <i id='EpsF2'><tr id='EpsF2'><dt id='EpsF2'><q id='EpsF2'><span id='EpsF2'><b id='EpsF2'><form id='EpsF2'><ins id='EpsF2'></ins><ul id='EpsF2'></ul><sub id='EpsF2'></sub></form><legend id='EpsF2'></legend><bdo id='EpsF2'><pre id='EpsF2'><center id='EpsF2'></center></pre></bdo></b><th id='EpsF2'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='EpsF2'><tfoot id='EpsF2'></tfoot><dl id='EpsF2'><fieldset id='EpsF2'></fieldset></dl></div>
                  • <tfoot id='EpsF2'></tfoot>
                      <bdo id='EpsF2'></bdo><ul id='EpsF2'></ul>

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

                          <tbody id='EpsF2'></tbody>
                        <legend id='EpsF2'><style id='EpsF2'><dir id='EpsF2'><q id='EpsF2'></q></dir></style></legend>

                          主站蜘蛛池模板: 九九伦理电影 | 成人在线一区二区三区 | 亚洲啊v在线 | 欧美福利一区 | 国产999精品久久久 精品三级在线观看 | 欧美精品一区二区三区四区 在线 | 亚洲精品电影 | 国产高清精品一区二区三区 | 亚洲第一天堂无码专区 | www久久久 | 欧美激情一区二区 | 久久er精品| 欧美aaaaaa| 黄色片在线看 | 成人免费毛片片v | 日韩在线免费视频 | 亚洲精选一区二区 | 福利视频一区二区 | 国产高清久久 | 亚洲福利一区 | 日韩免费视频一区二区 | 国产成人av一区二区三区 | 凹凸日日摸日日碰夜夜 | 国产精品日日做人人爱 | 91久久国产综合久久 | 免费精品 | 日韩视频在线免费观看 | 人人人干| 日日日色 | 国产成人精品一区二区三区在线观看 | 国产欧美精品区一区二区三区 | 国产日韩一区二区三免费高清 | 国产一区二区小视频 | 欧美日韩精品一区二区三区蜜桃 | 欧美激情亚洲激情 | 国外成人在线视频 | 精品一区二区三区在线观看 | 欧美videosex性极品hd | 欧美中文字幕一区二区 | 日韩一区二区三区四区五区 | 日韩一级免费看 |