RuntimeError with example in multiprocessing.spawn
Closed this issue · 1 comments
eric-brunner commented
Hi! I wanted to use your library, but got quickly stuck by this error. The concept is very interesting. I hope there is a solution to this issue :)
- Parallel TQDM version: 0.1.0
- Python version: 3.7
- Operating System: Windows 10
Description
Provided example raises RuntimeError in multiprocessing.spawn.
What I Did
from pqdm.processes import pqdm
# If you want threads instead:
# from pqdm.threads import pqdm
args = [
{'a': 1, 'b': 2},
{'a': 2, 'b': 3},
{'a': 3, 'b': 4},
{'a': 4, 'b': 5}
]
# args = range(1,6) would also work
def multiply(a, b):
return a*b
result = pqdm(args, multiply, n_jobs=2, argument_type='kwargs')
What I got
SUBMITTING | : 100%|██████████| 4/4 [00:00<00:00, 400.22it/s]
SUBMITTING | : 0%| | 0/4 [00:00<?, ?it/s]Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\multiprocessing\spawn.py", line 114, in _main
prepare(preparation_data)
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\multiprocessing\spawn.py", line 225, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
run_name="__mp_main__")
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\eric.brunner\Documents\Personnal\S1PR-E02-RDF-DPS\02_Development\Python\dps\test_parallel_loading.py", line 45, in <module>
result = pqdm(args, multiply, n_jobs=2, argument_type='kwargs')
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\site-packages\pqdm\processes.py", line 24, in pqdm
**kwargs
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\site-packages\pqdm\_base.py", line 47, in _parallel_process
for a in TQDM(iterable, **submitting_opts)
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\site-packages\pqdm\_base.py", line 47, in <listcomp>
for a in TQDM(iterable, **submitting_opts)
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\concurrent\futures\process.py", line 641, in submit
self._start_queue_management_thread()
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\concurrent\futures\process.py", line 583, in _start_queue_management_thread
self._adjust_process_count()
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\concurrent\futures\process.py", line 607, in _adjust_process_count
SUBMITTING | : 0%| | 0/4 [00:00<?, ?it/s] p.start()
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\multiprocessing\process.py", line 112, in start
self._popen = self._Popen(self)
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\multiprocessing\context.py", line 322, in _Popen
Traceback (most recent call last):
File "<string>", line 1, in <module>
return Popen(process_obj)
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\multiprocessing\popen_spawn_win32.py", line 46, in __init__
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\multiprocessing\spawn.py", line 143, in get_preparation_data
_check_not_importing_main()
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\multiprocessing\spawn.py", line 136, in _check_not_importing_main
is not going to be frozen to produce an executable.''')
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\multiprocessing\spawn.py", line 114, in _main
prepare(preparation_data)
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\multiprocessing\spawn.py", line 225, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
run_name="__mp_main__")
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\eric.brunner\Documents\Personnal\S1PR-E02-RDF-DPS\02_Development\Python\dps\test_parallel_loading.py", line 45, in <module>
result = pqdm(args, multiply, n_jobs=2, argument_type='kwargs')
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\site-packages\pqdm\processes.py", line 24, in pqdm
**kwargs
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\site-packages\pqdm\_base.py", line 47, in _parallel_process
for a in TQDM(iterable, **submitting_opts)
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\site-packages\pqdm\_base.py", line 47, in <listcomp>
for a in TQDM(iterable, **submitting_opts)
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\concurrent\futures\process.py", line 641, in submit
self._start_queue_management_thread()
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\concurrent\futures\process.py", line 583, in _start_queue_management_thread
self._adjust_process_count()
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\concurrent\futures\process.py", line 607, in _adjust_process_count
p.start()
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\multiprocessing\process.py", line 112, in start
self._popen = self._Popen(self)
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\multiprocessing\popen_spawn_win32.py", line 46, in __init__
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\multiprocessing\spawn.py", line 143, in get_preparation_data
_check_not_importing_main()
File "C:\Users\eric.brunner\Anaconda3\envs\dps\lib\multiprocessing\spawn.py", line 136, in _check_not_importing_main
is not going to be frozen to produce an executable.''')
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
SUBMITTING | : 0%| | 0/4 [00:00<?, ?it/s]
SUBMITTING | : 0%| | 0/4 [00:00<?, ?it/s]
PROCESSING | : 100%|██████████| 4/4 [00:00<00:00, 6.16it/s]
COLLECTING | : 100%|██████████| 4/4 [00:00<?, ?it/s]
niedakh commented
you need to add a "main" guard for windows: https://stackoverflow.com/questions/18204782/runtimeerror-on-windows-trying-python-multiprocessing