我正在尝试使用多处理流程,但出现此错误`RuntimeError: 尝试在启动新进程之前启动新进程。 当前进程已完成其引导阶段。
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.` but the issue is I have if __name__ == '__main__': already in my run.py file.
当我使用Google这个错误时,有人告诉我在已有if语句时添加它。
run.py
if __name__ == "__main__":
from inventory import update_inventory2
update_inventory2.py
print("update_inventory")
while True:
print("starting")
p = Process(target=add_to_queue, args=(db, ))# db is just the db being used and has no baring on my issue.
p.start()
p.join()
starting
update_inventory
starting
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python34\lib\multiprocessing\spawn.py", line 106, in spawn_main
exitcode = _main(fd)
File "C:\Python34\lib\multiprocessing\spawn.py", line 116, in _main
self = pickle.load(from_parent)
File "D:\Storage\\processes\update_inventory\update_inventory2.py", line 136, in <module>
p.start()
File "C:\Python34\lib\multiprocessing\process.py", line 105, in start
self._popen = self._Popen(self)
File "C:\Python34\lib\multiprocessing\context.py", line 212, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Python34\lib\multiprocessing\context.py", line 313, in _Popen
return Popen(process_obj)
File "C:\Python34\lib\multiprocessing\popen_spawn_win32.py", line 34, in __init__
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Python34\lib\multiprocessing\spawn.py", line 144, in get_preparation_data
_check_not_importing_main()
File "C:\Python34\lib\multiprocessing\spawn.py", line 137, 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.```
Should not be trying to run twice, not sure if it's related.