I need to use multiprocessing in a piece of code which is injected as string into exec
function:
code = """
from multiprocessing import Process
def f(name):
print('hello', name)
p = Process(target=f, args=('bob',))
p.start()
p.join()
"""
if __name__ == '__main__':
exec(code)
I get the following error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Programming\WinPython-64bit-3.3.5.0\python-3.3.5.amd64\lib\multiprocessing\forking.py", line 351, in main
self = load(from_parent)
AttributeError: 'module' object has no attribute 'f'
I am very new to multiprocessing... and I must say I have no idea what is wrong. My system is Windows 7 64-bit.
UPDATE: ... and a more general question: is it possible to run a user defined script (stored in a string) asynchronously in another process? This is actually what I try to achieve.