Ответ 1
Я бы опубликовал это как комментарий, так как у меня нет полного ответа, но я исправлю, когда выясню, что происходит.
from multiprocessing import Pool
def f(x):
return x**2
if __name__ == '__main__':
pool = Pool(4)
for res in pool.map(f,range(20)):
print(res)
Это работает. Я считаю, что ответ на этот вопрос здесь. Короче говоря, подпроцессы не знают, что они являются подпроцессами и пытаются рекурсивно запустить основной script.
Это ошибка, которую я даю, что дает нам одно и то же решение:
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.