久久久久久久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>

                          主站蜘蛛池模板: 天天操夜夜看 | 亚洲精品视频免费 | 日韩中文字幕免费在线观看 | 一本色道精品久久一区二区三区 | 超碰免费在 | 亚洲资源在线 | 久久91| 欧美精品啪啪 | 韩日有码 | 亚洲欧洲色视频 | 久久中文字幕一区 | 国产精品国产三级国产aⅴ中文 | 日韩激情在线 | 国产1区| 亚洲欧美日韩中文字幕一区二区三区 | 国产一区二区三区 | 国产韩国精品一区二区三区 | 特级a欧美做爰片毛片 | 日韩人体视频 | 超碰成人免费 | 激情欧美一区二区三区中文字幕 | 欧美精品中文字幕久久二区 | 资源首页二三区 | 天天操网| 中文字幕亚洲区一区二 | 精品欧美乱码久久久久久1区2区 | 亚洲一区视频在线 | 久久精品国产精品青草 | 国产一区二区三区四区 | 蜜桃视频在线观看免费视频网站www | 欧美日韩国产一区二区 | 欧美一区二区在线 | 黄色网络在线观看 | 婷婷精品| 国产精品视频一区二区三区 | 五月婷婷色 | 成人免费视频在线观看 | 精品欧美一区二区精品久久久 | 一区二区三区回区在观看免费视频 | 国产精品久久片 | 九九国产在线观看 |