pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    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="hxdf7zt" 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="hxlxn57" 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="5tt55zt" 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>

                          主站蜘蛛池模板: 武汉高低温试验箱_恒温恒湿试验箱厂家-武汉蓝锐环境科技有限公司 | Eiafans.com_环评爱好者 环评网|环评论坛|环评报告公示网|竣工环保验收公示网|环保验收报告公示网|环保自主验收公示|环评公示网|环保公示网|注册环评工程师|环境影响评价|环评师|规划环评|环评报告|环评考试网|环评论坛 - Powered by Discuz! | GEDORE扭力螺丝刀-GORDON防静电刷-CHEMTRONICS吸锡线-上海卓君电子有限公司 | 彩信群发_群发彩信软件_视频短信营销平台-达信通| 硬齿面减速机_厂家-山东安吉富传动设备股份有限公司 | 展厅设计公司,展厅公司,展厅设计,展厅施工,展厅装修,企业展厅,展馆设计公司-深圳广州展厅设计公司 | 上海宿田自动化设备有限公司-双面/平面/单面贴标机 | T恤衫定做,企业文化衫制作订做,广告T恤POLO衫定制厂家[源头工厂]-【汉诚T恤定制网】 | 上海软件开发-上海软件公司-软件外包-企业软件定制开发公司-咏熠科技 | 通信天线厂家_室分八木天线_对数周期天线_天线加工厂_林创天线源头厂家 | 温州中研白癜风专科_温州治疗白癜风_温州治疗白癜风医院哪家好_温州哪里治疗白癜风 | 电车线(用于供电给电车的输电线路)-百科| 桥架-槽式电缆桥架-镀锌桥架-托盘式桥架 - 上海亮族电缆桥架制造有限公司 | 北京发电机出租_发电机租赁_北京发电机维修 - 河北腾伦发电机出租 | 江苏齐宝进出口贸易有限公司| 三轴曲线机-端子插拔力试验机|华杰仪器| 自动螺旋上料机厂家价格-斗式提升机定制-螺杆绞龙输送机-杰凯上料机 | 天坛家具官网 | ★店家乐|服装销售管理软件|服装店收银系统|内衣店鞋店进销存软件|连锁店管理软件|收银软件手机版|会员管理系统-手机版,云版,App | 超高频感应加热设备_高频感应电源厂家_CCD视觉检测设备_振动盘视觉检测设备_深圳雨滴科技-深圳市雨滴科技有限公司 | 行吊_电动单梁起重机_双梁起重机_合肥起重机_厂家_合肥市神雕起重机械有限公司 | 纸箱抗压机,拉力机,脂肪测定仪,定氮仪-山东德瑞克仪器有限公司 | 老城街小面官网_正宗重庆小面加盟技术培训_特色面馆加盟|牛肉拉面|招商加盟代理费用多少钱 | 北京征地律师,征地拆迁律师,专业拆迁律师,北京拆迁律师,征地纠纷律师,征地诉讼律师,征地拆迁补偿,拆迁律师 - 北京凯诺律师事务所 | 多功能干燥机,过滤洗涤干燥三合一设备-无锡市张华医药设备有限公司 | 上海防爆真空干燥箱-上海防爆冷库-上海防爆冷柜?-上海浦下防爆设备厂家? | 地图标注-手机导航电子地图如何标注-房地产商场地图标记【DiTuBiaoZhu.net】 | 控显科技 - 工控一体机、工业显示器、工业平板电脑源头厂家 | 房间温控器|LonWorks|海思 | 二手Sciex液质联用仪-岛津气质联用仪-二手安捷伦气质联用仪-上海隐智科学仪器有限公司 | LINK FASHION 童装·青少年装展 河南卓美创业科技有限公司-河南卓美防雷公司-防雷接地-防雷工程-重庆避雷针-避雷器-防雷检测-避雷带-避雷针-避雷塔、机房防雷、古建筑防雷等-山西防雷公司 | 鄂泉泵业官网|(杭州、上海、全国畅销)大流量防汛排涝泵-LW立式排污泵 | 运动木地板厂家_体育木地板安装_篮球木地板选购_实木运动地板价格 | 杭州中央空调维修_冷却塔/新风机柜/热水器/锅炉除垢清洗_除垢剂_风机盘管_冷凝器清洗-杭州亿诺能源有限公司 | 深圳货架厂_仓库货架公司_重型仓储货架_线棒货架批发-深圳市诺普泰仓储设备有限公司 | 法兰螺母 - 不锈钢螺母制造厂家 - 万千紧固件--螺母街 | 欧盟ce检测认证_reach检测报告_第三方检测中心-深圳市威腾检验技术有限公司 | 滑板场地施工_极限运动场地设计_滑板公园建造_盐城天人极限运动场地建设有限公司 | 流量卡中心-流量卡套餐查询系统_移动电信联通流量卡套餐大全 | 东莞压铸厂_精密压铸_锌合金压铸_铝合金压铸_压铸件加工_东莞祥宇金属制品 | 挤塑板-XPS挤塑板-挤塑板设备厂家[襄阳欧格] |