How can I start a multiprocessing.Process from within __init__()
of a class, targeting another function in that class? The class itself shall not be a process. __init__()
shall refer to a class variable assigned in the class, not inside any function.
Working code:
import multiprocessing as mp
class SomeClass:
def __init__(self):
p_process1 = mp.Process(target=self.process1)
p_process1.start()
def process1(self):
while True:
pass
The code I want:
import multiprocessing as mp
class SomeClass:
def __init__(self):
self.p_process1.start()
def process1(self):
while True:
pass
p_process1 = mp.Process(target=process1)
If I now try to run the code I want, I get an error message:
Process Process-1:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/multiprocessing/process.py", line 249, in _bootstrap
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
TypeError: process1() missing 1 required positional argument: 'self'