Nour
Nour

Reputation: 79

runtime error: Multiprocessing (python 3.9)

I am trying to run the code available here https://github.com/GDPlumb/MAPLE/blob/master/1-Accuracy/run.py but the following error occurs. Any idea how can I solve it

child processes and you have forgotten to use the proper idiom                          

main
in the
module :
if name main freeze=support() --
"The ""freeze_support()"" line can be omitted if the program"
"return Pool(processes, initializer, initargs, rnaxtasksperchild,"
"File ""C:\Python39\lib\multiprocessing\pool.py"", line 212, in init"
"File ""C:\Python39\lib\multiprocessing\pool.py"", line 303, return self._repopulate_pool_static(self._ctx, self.Pro"
"File ""C:\Python39\lib\multiprocessing\pool.py"", line 326,"
w.start()
"""C:\Python39\lib\multiprocessing\process.py"", line 121, in start lf._popen = self._Popen(self)"
_static
"in _repopulate_pool cess,"
in _repopulate_pool
File se
File re """C:\Python39\lib\multiproce ssing\context.py"", line 327, in turn Popen(process_obj)" _Popen "File ""C:\Python39\lib\multiproce ssing\popen_spawn_win32.py"", line 45,"

prep_data = spawn .get_preparation_data(process_obj._name)
"File ""c:\Python39\lib\multiprocessing\spawn .py"", line 154,in get_preparation_data"
_check_not_importing
main ()
main
"File ""C:\Python39\lib\multiprocessing\spawn .py"",line 134,in check_not_importing raise RuntimeError ('''"
RuntimeError :
before
An attempt has been made to start a new process current process has finished its bootstrapping phase .
This probably means that you are not using fork to
the
your
start
child processes and you have forgotten to use the proper idiom in the main module:
if name main reeze_support()
"The ""freeze_support()"" line can be omitted if the program"
is
"l.py"","
"File ""C:\Python39\lib\multiprocessing\poo"
"line 326, in _repopulate_pool_static"
"File ""C:\Python39\lib\multiprocessing\process.py"", line 121, in start"
"File ""C:\Python39\lib\multiproce ssin \context. "" line 327, in Popen"

P.S: I tried adding if __name__ == '__main__': pool = Pool(12) pool.map(run, args)

Traceback (most recent call last): Traceback (most recent call last): "File """", line 1, in Traceback (most recent call last): Traceback (most recent call last):" "File """", line 1, in " "File ""c:\Python39\lib\rrultiprocessing\spawn .py"", line 116, in spawn_main exitcode = _main(fd, parent_sentinel)" "File ""c:\Python39\lib\rrultiprocessing\spawn .py"", line 125, in main" "File ""c:\Python39\lib\rnultiprocessing\spawn .py"", line 116, in spawn_main File """", line 1, in " Traceback (roost recent call last): "Traceback (roost recent call last): File """", line 1, in " "File ""c:\Python39\lib\rnultiprocessing\spawn.py'', line 125,in main prepare(preparation_data)" "File ""c:\Python39\lib\multiprocessing\spawn .py"",line 236,in prepare" _fixup_main_from_path(data['init_main_from_path']) "File ""c:\Python39\lib\multiprocessing\spawn .py"",line 287,in _fixup_main_from_path main_content = runpy.run_path(main_path," "File ""c:\Python39\lib\runpy.py'', line 268, in run_path return _run_module_code(code, init_globals, run_name," "File ""c:\Python39\lib\runpy.py'', line 97, in _run_module_code exitcode = _main(fd, parent_sentinel)" "File ""c:\Python39\lib\multiprocessing\spawn .py"", line 116, in spawn_main File ""c:\Python39\lib\multiprocessing\spawn .py"", line 116, in spawn_main File ""'', line 1, in " "Traceback (most recent call last): File """", line 1, in " "File ""c:\Python39\lib\rrultiprocessing\spawn .py'', line 125, in main"

Upvotes: 0

Views: 1518

Answers (1)

zerocog
zerocog

Reputation: 1763

You must set the multiprocessing Contexts and start methods

For my case, I had to utilize the context 'fork'

ctx = multiprocessing.get_context('fork')
work_queue    = ctx.Queue()
results_queue = ctx.Queue()
...
 workers = get_worker_processes(
    _process_data,
    (task_function, work_queue, results_queue),
    nproc=nproc,
)          
.....
workers = [
    ctx.Process(target=f, args=args) for _ in range(num_procs)
]   

Follow the guidance given in the Python multiprocessing documentation for the link referenced. Notice the change in defaults.

Contexts and start methods Depending on the platform, multiprocessing supports three ways to start a process. These start methods are

spawn The parent process starts a fresh python interpreter process. The child process will only inherit those resources necessary to run the process object’s run() method. In particular, unnecessary file descriptors and handles from the parent process will not be inherited. Starting a process using this method is rather slow compared to using fork or forkserver.

Available on Unix and Windows. The default on Windows and macOS.

fork The parent process uses os.fork() to fork the Python interpreter. The child process, when it begins, is effectively identical to the parent process. All resources of the parent are inherited by the child process. Note that safely forking a multithreaded process is problematic.

Available on Unix only. The default on Unix.

forkserver When the program starts and selects the forkserver start method, a server process is started. From then on, whenever a new process is needed, the parent process connects to the server and requests that it fork a new process. The fork server process is single threaded so it is safe for it to use os.fork(). No unnecessary resources are inherited.

Available on Unix platforms which support passing file descriptors over Unix pipes.

Changed in version 3.8: On macOS, the spawn start method is now the default. The fork start method should be considered unsafe as it can lead to crashes of the subprocess. See bpo-33725.

Changed in version 3.4: spawn added on all unix platforms, and forkserver added for some unix platforms. Child processes no longer inherit all of the parents inheritable handles on Windows.

Upvotes: 1

Related Questions