我试图在Windows 10 64bit,Python 3.7中使用多处理,并且在Ubuntu python 3.7中可以轻松使用,但是在Windows中,它会引发错误。 该Basepea继承自
class BasePea(metaclass=PeaMeta):
"""BasePea is an unary service unit which provides network interface and
communicates with others via protobuf and ZeroMQ
"""
def __init__(self, args: Union['argparse.Namespace', Dict]):
""" Create a new :class:`BasePea` object
:param args: the arguments received from the CLI
:param replica_id: the id used to separate the storage of each pea, only used when ``args.separate_storage=True``
"""
super().__init__()
self.args = args
self.name = self.__class__.__name__ #: this is the process name
self.daemon = True
self.is_ready = _get_event(self)
self.is_shutdown = _get_event(self)
self.ready_or_shutdown = _make_or_event(self, self.is_ready, self.is_shutdown)
self.is_shutdown.clear()
def start(self):
super().start()
if isinstance(self.args, dict):
_timeout = getattr(self.args['peas'][0], 'timeout_ready', 5e3) / 1e3
else:
_timeout = getattr(self.args, 'timeout_ready', 5e3) / 1e3
if self.ready_or_shutdown.wait(_timeout):
if self.is_shutdown.is_set():
self.logger.critical(f'fail to start {self.__class__} with name {self.name}')
return self
else:
raise TimeoutError(
f'{self.__class__} with name {self.name} can not be initialized after {_timeout * 1e3}ms')
def __enter__(self):
return self.start()
def __exit__(self, exc_type, exc_val, exc_tb):
self.close()
错误是
File "C:\Users\PC\anaconda3\lib\multiprocessing\process.py", line 112, in start
self._popen = self._Popen(self)
File "C:\Users\PC\anaconda3\lib\multiprocessing\context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Users\PC\anaconda3\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "C:\Users\PC\anaconda3\lib\multiprocessing\popen_spawn_win32.py", line 89, in __init__
reduction.dump(process_obj, to_child)
File "C:\Users\PC\anaconda3\lib\multiprocessing\reduction.py", line 73, in dump
ForkingPickler(file, protocol).dump(obj)
_pickle.PicklingError: Can't pickle <class 'jina.peapods.pea.BasePea'>: it's not the same object as jina.peapods.pea.BasePea