python - PyCurl. 'Can't pickle Curl object' error on Windows x64 -
import multiprocessing import time import pycurl class bot(multiprocessing.process): def __init__(self): multiprocessing.process.__init__(self) self.c = pycurl.curl() def run(self): pass if __name__ == '__main__': bot().start() this code works on ubuntu 13.04 x64, fails on windows 7 x64/server 2008 x64. use pycurl 7.19.0 , python 2.7. error is:
z:\bot>python test.py traceback (most recent call last): file "test.py", line 74, in <module> bot().start() file "c:\python27\lib\multiprocessing\process.py", line 104, in start self._popen = popen(self) file "c:\python27\lib\multiprocessing\forking.py", line 244, in __init__ dump(process_obj, to_child, highest_protocol) file "c:\python27\lib\multiprocessing\forking.py", line 167, in dump forkingpickler(file, protocol).dump(obj) file "c:\python27\lib\pickle.py", line 224, in dump self.save(obj) file "c:\python27\lib\pickle.py", line 331, in save self.save_reduce(obj=obj, *rv) file "c:\python27\lib\pickle.py", line 419, in save_reduce save(state) file "c:\python27\lib\pickle.py", line 286, in save f(self, obj) # call unbound method explicit self file "c:\python27\lib\pickle.py", line 649, in save_dict self._batch_setitems(obj.iteritems()) file "c:\python27\lib\pickle.py", line 681, in _batch_setitems save(v) file "c:\python27\lib\pickle.py", line 313, in save (t.__name__, obj)) pickle.picklingerror: can't pickle 'curl' object: <pycurl.curl object @ 0x00000 00002360478> z:\bot>traceback (most recent call last): file "<string>", line 1, in <module> file "c:\python27\lib\multiprocessing\forking.py", line 347, in main self = load(from_parent) file "c:\python27\lib\pickle.py", line 1378, in load return unpickler(file).load() file "c:\python27\lib\pickle.py", line 858, in load dispatch[key](self) file "c:\python27\lib\pickle.py", line 880, in load_eof raise eoferror eoferror why happens?
on posix systems, multiprocessing works using fork() syscall, clones running process, , of state (including things instances of complex classes, such pycurl.curl).
windows not have fork(), or it, multiprocessing fires new python interpreter each child process, special stub function listens parent process , recreates state looks had fork() been used. key technique used multiprocessing recreates each object in child process, parent process, used. works converting objects bytecode representation (using pickle module), sending them on pipe child, , converting them python objects once there.
for kinds of python objects, works perfectly, , transparent you. there number of obvious kinds of things cannot possibly work; open files cannot passed around in way; nor can state of non-python library objects, don't know pickle system. unfortunately, pycurl bit of both of these things.
Comments
Post a Comment