I have a project for my college regarding multiprocessing in python.For my python projects I use spyder in windows. Therefore im trying to run a very trivial multi - processing code in spyder but every time i run it spyder console freezes and never finishes. This is my code:
from multiprocessing import Pool, freeze_support
import multiprocessing
def f(i):
return i+1
def main():
pool = multiprocessing.Pool(4)
result = pool.map(f, range(4))
pool.close()
pool.join()
print result
if __name__ == '__main__':
freeze_support() #you need this in windows
main()
I have noticed this is a common issue with multi-proccesing and the lack of fork in windows, therefore i took into account the paragraph 16.6.3.2. Windows in https://docs.python.org/2/library/multiprocessing.html#windows .
I also avoided printing from my child process as stated here:Simple Python Multiprocessing function doesn't output results and instead used return.
My code works if i run it from a unix terminal, but i'm mainly using windows for my python projects. Is there a workaround for this issue in windows?