我有一个大代码需要一段时间来进行计算,我决定学习多线程和多处理,因为我的处理器只有 20% 用于进行计算。在多线程没有任何改进之后,我决定尝试多处理,每当我尝试使用它时,即使在非常简单的代码上也只会显示很多错误。
这是我的大型计算繁重代码开始出现问题后测试的代码:
from concurrent.futures import ProcessPoolExecutor
def func():
print("done")
def func_():
print("done")
def main():
executor = ProcessPoolExecutor(max_workers=3)
p1 = executor.submit(func)
p2 = executor.submit(func_)
main()
在我遇到的错误消息中说
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()
...
这不是全部信息,因为它非常大,但我认为我可能会有所帮助以帮助我。错误消息中的几乎所有其他内容都类似于“行中的错误 ... in ...”
如果它可能有帮助,大代码位于:https ://github.com/nobody48sheldor/fuseeinator2.0 它可能不是最新版本。