PicklingError: Can ‘t pickling & lt; The type ‘instancemethod & gt; : attribute lookup builtin.instancemethod failed
The Python2
** library: **multiprocessing. Pool
problem description: use the method of the class to pool. Apply_async for parameter passing error
solution: cannot use the method of the class directly copy, call the method of the class through the intermediate function, and then use the intermediate function for apply_async for parameter passing.
complete code:
#coding=utf-8
import time
from multiprocessing import Pool
class Attack:
def __init__(self):
pass
def run(self, data):
print '[+] ' + data + "attack exploit."
time.sleep(3)
return {'data': data}
# + ---------------------------------下面是一起的--------------------------------------
attacker = Attack()
def conumers_wrapper(data):
return attacker.run(data)
class Test:
def __init__(self):
pass
def _save_result(self, data):
try:
print '[-] _save_result -> ', data
except Exception as e:
print e
def main(self):
name = 'aquaman'
pool = Pool(processes=20)
for _ in range(10):
# func[, args=()[, kwds={}[, callback=None]]]
pool.apply_async(conumers_wrapper, (name,), callback=self._save_result)
pool.close()
pool.join()
print "[*] finished."
if __name__ == '__main__':
Test().main()
div>
Read More:
- cpickle.picklingerror can’t pickle type ‘module’ attribute lookup __builtin__.module failed
- KeyError: “Can‘t open attribute (can‘t locate attribute: ‘nrx‘)“
- AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘H:\\yolov5-5.0\\models\\
- AttributeError: Can‘t get attribute ‘LeNet‘ on <module ‘__ main__ “From (error in torch loading model)
- Python-cp950‘ codec can‘t encode
- Python error TypeError:can ‘t convert complex to float
- TypeError: object of type ‘builtin_function_or_method’ has no len()
- Java gets the type t.class of generic t
- Python error: resource u’tokenizers / Punkt/ english.pickle ‘ not found.
- Python error prompt: typeerror: ‘builtin’_ function_ or_ method‘ object is not subscriptable
- Can’t find Python executable “D:\python3\python.exe”, you can set the PYTHON env variable.
- [Solved] CAP_IMAGES: can‘t find starting number (in the name of file)
- chatbot error: [E941] Can‘t find model ‘en‘
- SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: truncated \UX
- Error (12153): Can‘t elaborate top-level user hierarchy
- java.lang.IllegalArgumentException: error at ::0 can‘t find referenced pointcut anyMethod
- 2003 – Can‘t connect to MySQL server on ‘192.168.163.128‘(Unknown error )
- AttributeError: type object ‘Image‘ has no attribute ‘open‘
- UnhandledPromiseRejectionWarning Error: Can‘t set headers after they are sent (How to Fix)
- UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xc3 in position 54: invalid continuation byte