In Python on can easily do
from multiprocessing import Process import os
def info(title):
print(title)
print('module name:', __)
print('parent process:', os.getppid())
print('process id:', os.getpid())
def f(name):
info('function f')
print('hello', name)
if __name__ == '__main__':
info('main line')
p = Process(target=f, args=('bob',))
p.start()
p.join()
to run even a simple function inside a separate process. We can go further an create instances of classes that are loaded inside a separate process:
class FooClass:
def __init__(self, ...some args...):
...
foo = Process(
target=FooClass,
args=(...some args for the constructor of Foo...)
)
bar.start()
How would I do that in Qt using QProcess
if possible at all? I am interested in this approach since I want to use it in C++ as well as PySide/PyQt. I know I can just create another project where the generated binary (containing only that class and its instance) is ran as the command passed onto the QProcess
instance but this is not what I am looking for. Not to mention that, correct me if I'm wrong, in the Python case the spawned process gets a "copy" of the working set of the parent. If I am to just create another application and run it, this is clearly not the case.
