При попытке добавить только что созданный
multiprocessing.Process в
multiprocessing.Manager().dict() возникает следующая ошибка
Traceback (most recent call last):
File "main.py", line 36, in <module>
start_old_tasks.start_old_tasks(manager_process_task)
File "/root/subserver/start_old_tasks.py", line 21, in start_old_tasks
manager_process_task.continue_task(
File "/root/subserver/cheating/manager_process_task.py", line 186, in continue_task
task_processes_.update({uuid: [prcs, "simple_vote"]})
File "<string>", line 2, in update
File "/usr/lib/python3.8/multiprocessing/managers.py", line 834, in _callmethod
conn.send((self._id, methodname, args, kwds))
File "/usr/lib/python3.8/multiprocessing/connection.py", line 206, in send
self._send_bytes(_ForkingPickler.dumps(obj))
File "/usr/lib/python3.8/multiprocessing/reduction.py", line 51, in dumps
cls(buf, protocol).dump(obj)
TypeError: cannot pickle 'weakref' object
Вот сам код
task_processes = Manager().dict()
prcs = Process(
target=start_prcss__simple_vote_start,
args=[
uuid, data_info,
sql_request, logger
],
daemon=True
)
prcs.start()
task_processes.update({uuid: [prcs, "simple_vote"]})
Так же чтобы обойти "защиту" процессов, я переопределил класс
Process
class Process(Process):
def __init__(self, **args):
super(Process, self).__init__(**args)
print("Object", self, "created.")
def run(self):
print("Object", self, "process started.")
def __getstate__(self):
state = self.__dict__.copy()
conf = state['_config']
if 'authkey' in conf:
conf['authkey'] = bytes(conf['authkey'])
return state
def __setstate__(self, state):
state['_config']['authkey'] = AuthenticationString(state['_config']['authkey'])
self.__dict__.update(state)