, . : yield return, sq . Pool .
, Windows .
Attempt to start a new process before the current process
has finished its bootstrapping phase.
This probably means that you are on Windows and you have
forgotten to use the proper idiom in the main module:
if __name__ == '__main__':
, , :
, python, python .., "if main block" "
__name__=="__main__" :
from multiprocessing import Pool
def sq(x):
return x**2
if __name__=="__main__":
p = Pool(2)
n = p.map(sq, range(10))
print(n)
:
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
: , imap
n = p.imap(sq, range(10))
n -. ( ), , ,
print(list(n))
, , imap , map