1.11M Members

multiprocessing blues in Windows7

 
0
 

This example program of using the multiprocessing is crashing my i7 4 core windows7 64 bit computer (32 bit enthought Python 2.7), but is running fine in virtual machine Ubuntu with 4 cores assigned. Can anyone run it in their commputer in Windows7. My system memory (8 GB) is totally eaten by the program and mouse moves but I can not do anything with computer, even ctrl-alt-del to get to task manager.

# -*- coding: utf-8 -*-
from numpy import arange,sqrt, random, linalg
from multiprocessing import Pool

global counter
counter = 0
def cb(r):
    global counter
    print counter, r
    counter +=1

def det(M):
    return linalg.det(M)

po = Pool()
for i in xrange(1,300):
    j = random.normal(1,1,(100,100))
    po.apply_async(det,(j,),callback=cb)
po.close()
po.join()
print counter

http://pyinsci.blogspot.fi/2009/02/usage-pattern-for-multiprocessing.html

 
2
 

I found out that in windows the creation of Pool must be guarded by

if __name__ == '__main__': 

as the module is imported by interpreter. So this works:

# -*- coding: utf-8 -*-
from numpy import arange,sqrt, random, linalg
from multiprocessing import Pool

global counter
counter = 0
def cb(r):
    global counter
    print counter, r
    counter +=1

def det(M):
    return linalg.det(M)

if __name__ == '__main__':
    po = Pool(2)
    for i in xrange(1,100):
        j = random.normal(1,1,(100,100))
        po.apply_async(det,(j,),callback=cb)
    po.close()
    po.join()
    print counter
Question Self-Answered as of 1 Year Ago
 
0
 

Thanks for letting us know!

Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: