日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ERROR: Process pool report error: Can‘t pickle

發(fā)布時間:2025/3/15 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ERROR: Process pool report error: Can‘t pickle 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

注意:如果出現

PicklingError: Can't pickle <type 'instancemethod'>: attribute lookup __builtin__.instancemethod failed

數據序列化

  • https://zhidao.baidu.com/question/525917268.html
  • https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/00138683221577998e407bb309542d9b6a68d9276bc3dbe000

應該是說一個數據結構,比如二叉樹之類,序列化以后會變成一個char數組或者一個string字符串這樣,方便你存到文件里面或者通過網絡傳輸。然后要恢復的時候就是“反序列化”,把文件里讀出來/從網絡收到的char數組或者string恢復成一棵二叉樹或者其他什么東西。主要就是方便保存

可以被序列化的類型有:

https://zhidao.baidu.com/question/619353578954760372.html

* None,True 和 False;
* 整數,浮點數,復數;
* 字符串,字節(jié)流,字節(jié)數組;
* 包含可pickle對象的tuples,lists,sets和dictionaries;
* 定義在module頂層的函數:
* 定義在module頂層的內置函數;
* 定義在module頂層的類;
* 擁有dict()或setstate()的自定義類型;

https://stackoverflow.com/questions/8804830/python-multiprocessing-pickling-error

The problem is that the pool methods all use a queue.Queue to pass tasks to the worker processes. Everything that goes through the queue.Queue must be pickable, and foo.work is not picklable since it is not defined at the top level of the module.
It can be fixed by defining a function at the top level

大意是類中的方法不能被序列化,而進程中的參數或者函數必須被序列化,所以報錯

解決:

import multiprocessingdef func(x):return x*xclass someClass(object):def __init__(self,func):self.f = funcdef go(self):pool = multiprocessing.Pool(processes=4)#result = pool.apply_async(self.f, [10])#print result.get(timeout=1)print pool.map(self.f, range(10))a=someClass(func) a.go()

defining a function at the top level
將進程需要調用的函數變成定義在module頂層的函數

解決過程中又出現的問題:
1. con = multiprocessing.Process(target=self.connect, args=(k, metrics, request, return_dict, ))
同樣是PicklingError: Can’t pickle錯誤
原因是:

type(metrics) <type 'dict'>

雖然metrics的類型是dict但是里面的具體內容是

'vmware_vm_net_transmitted_average': <prometheus_client.core.GaugeMetricFamily object at 0x7161650>

也會報PicklingError: Can’t pickle

可能是里里面的<prometheus_client.core.GaugeMetricFamily object at 0x7161650>不能被序列化

總結

以上是生活随笔為你收集整理的ERROR: Process pool report error: Can‘t pickle的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。