Hello I have got a tough problem because I have to return value from target Process function. I can't use Manager to retrieve value from this because I made assembly method which takes only 5 arguments and it will be hard to remake this.I 've created class which inherit from Process class (Here is the code)
class ProcessWithReturnValue(Process):
def __init__(self, group=None, target=None, name=None, args=(), kwargs={},
*, daemon=None):
super().__init__(group=group, target=target, name=name, args=args, kwargs=kwargs, daemon=daemon)
self._return = None
def run(self):
if self._target:
self._return = self._target(*self._args, **self._kwargs)
def join(self):
super().join()
return self._return
My code where I'am starting and joining Processes is here:
if(rbValue.get() == 2):
if (i != numberOfThreads - 1):
processes.append(ProcessWithReturnValue(target=ThreadFunctionWithArrays, args=(
i * rowsPerThread, (i + 1) * rowsPerThread, width, copyImgLeft, copyImgRight)))
processes[i].start()
else:
processes.append(ProcessWithReturnValue(target=ThreadFunctionWithArrays, args=(
i * rowsPerThread, height, width, copyImgLeft, copyImgRight)))
processes[i].start()
----------------------------------------------------------------------------------------------
for i in range(0, numberOfThreads):
if pixelArray is None:
pixelArray = processes[i].join()
else:
toAppend = processes[i].join()
pixelArray = np.append(pixelArray, toAppend, axis=0)
I have no errors but, what .join function returns is None
Here is also python function which I wrote to test this process
def ThreadFunctionWithArrays(startPointY, endPointY, pixelsWidth, pixelsArray1, pixelsArray2):
numberOfRows = endPointY - startPointY
pixelArray = GenerateEmptyPartMatrix(pixelsWidth, numberOfRows)
y = 0
for j in range(startPointY, endPointY):
for i in range(0, pixelsWidth):
r1, g1, b1 = pixelsArray1.getpixel((i, j))
r2, g2, b2 = pixelsArray2.getpixel((i, j))
pixelArray[y][i] = (
r1 * 0.4561 + g1 * 0.500484 + b1 * 0.176381 - r2 * 0.0434706 - g2 * 0.0879388 - b2 * 0.00155529,
- r1 * 0.0400822 - g1 * 0.0378246 - b1 * 0.0157589 + r2 * 0.378476 + g2 * 0.73364 - b2 * 0.0184503,
- r1 * 0.0152161 - g1 * 0.0205971 - b1 * 0.00546856 - r2 * 0.0721527 - g2 * 0.112961 + b2 * 1.2264)
y += 1
return pixelArray
How should i write a proper class which inherits from Process and can return a value with join() method?
here is link to python process.py: https://github.com/python/cpython/blob/master/Lib/multiprocessing/process.py
EDIT: I am not interested in different approaches for my problem. I want to try override join function.