Я пытаюсь передать список процессу, который запускает функцию сравнения цветов. Затем я хочу, чтобы эти цвета были возвращены в список, чтобы я мог использовать их в функции вне процесса. Как я могу это сделать?
Все, что у меня есть до сих пор, это суженная проблема, которую я затем упростил для примера:
import multiprocessing
def test(c):
c[0] = 1
class TestClass:
def __init__(self):
with multiprocessing.Manager() as manager:
colorcodes = manager.list()
p = multiprocessing.Process(target=test, args=(colorcodes,))
p.start()
p.join()
print(colorcodes[0])
if __name__ == '__main__':
TestClass()
Что возвращает:
Process Process-2:
Traceback (most recent call last):
File "C:\Users\usr\AppData\Local\Programs\Python\Python37\lib\multiprocessing\process.py", line 297, in _bootstrap
self.run()
File "C:\Users\usr\AppData\Local\Programs\Python\Python37\lib\multiprocessing\process.py", line 99, in run
self._target(*self._args, **self._kwargs)
File "D:\Python Development\example_env\example.py", line 5, in test
c[0] = 1
File "<string>", line 2, in __setitem__
File "C:\Users\usr\AppData\Local\Programs\Python\Python37\lib\multiprocessing\managers.py", line 834, in _callmethod
raise convert_to_error(kind, result)
IndexError: list assignment index out of range
Traceback (most recent call last):
File "C:\Users\usr\AppData\Local\Programs\Python\Python37\lib\multiprocessing\managers.py", line 811, in _callmethod
conn = self._tls.connection
AttributeError: 'ForkAwareLocal' object has no attribute 'connection'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "example.py", line 19, in <module>
TestClass()
File "example.py", line 15, in __init__
print(colorcodes[0])
File "<string>", line 2, in __getitem__
File "C:\Users\usr\AppData\Local\Programs\Python\Python37\lib\multiprocessing\managers.py", line 815, in _callmethod
self._connect()
File "C:\Users\usr\AppData\Local\Programs\Python\Python37\lib\multiprocessing\managers.py", line 802, in _connect
conn = self._Client(self._token.address, authkey=self._authkey)
File "C:\Users\usr\AppData\Local\Programs\Python\Python37\lib\multiprocessing\connection.py", line 490, in Client
c = PipeClient(address)
File "C:\Users\usr\AppData\Local\Programs\Python\Python37\lib\multiprocessing\connection.py", line 691, in PipeClient
_winapi.WaitNamedPipe(address, 1000)
FileNotFoundError: [WinError 2] The system cannot find the file specified
Я использую Python версию 3.7.6 на Windows 10 Home 64-bit v.1909