concurrency - Why does Python refuse to execute this code in a new subprocess? -
i trying make simple application allows people define own little python scripts within application. want execute code in new process make easy kill later. unfortunately, python keeps giving me following error:
traceback (most recent call last): file "<stdin>", line 1, in <module> file "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile execfile(filename, namespace) file "/home/skylion/documents/python_exec test.py", line 19, in <module> code_process = process(target=exec_, args=(user_input_code)) file "/usr/lib/python2.7/multiprocessing/process.py", line 104, in __init__ self._args = tuple(args) typeerror: 'code' object not iterable >>>
my code posted below
user_input_string = ''' import os world_name='world' robot_name='default_body + os.path.sep' joint_names=['hingejoint0', 'hingejoint1', 'hingejoint2', 'hingejoint3', 'hingejoint4', 'hingejoint5', 'hingejoint6', 'hingejoint7', 'hingejoint8'] print(joint_names) ''' def exec_(arg): exec(arg) user_input_code = compile(user_input_string, 'user_defined', 'exec') multiprocessing import process code_process = process(target=exec_, args=(user_input_code)) code_process.start()
what missing? there wrong user_input_string? compile options? appreciated.
i believe args
must tuple. create single-element tuple, add comma so: args=(user_input_code,)
Comments
Post a Comment