Problem with stackless python, cannot write to a dict

Posted by ANON on Stack Overflow See other posts from Stack Overflow or by ANON
Published on 2010-05-25T02:34:44Z Indexed on 2010/05/25 2:41 UTC
Read the original article Hit count: 422

Filed under:
|
|

I have simple map-reduce type algorithm, which I want to implement in python and make use of multiple cores.

I read somewhere that threads using native thread module in 2.6 dont make use of multiple cores. is that true?

I even implemented it using stackless python however i am getting into weird errors [Update: a quick search showed that the stack less does not allows multiple cores So are their any other alternatives?]

def Propagate(start,end):
print "running Thread with range: ",start,end
def maxVote(nLabels):
    count = {}
    maxList = []
    maxCount = 0
    for nLabel in nLabels:
        if nLabel in count:
            count[nLabel] += 1
        else:
            count[nLabel] = 1
    #Check if the count is max
        if count[nLabel] > maxCount:
            maxCount = count[nLabel];
            maxList = [nLabel,]
        elif count[nLabel]==maxCount:
            maxList.append(nLabel)
    return random.choice(maxList)        

for num in range(start,end):
    node=MapList[num]
    nLabels = [Label[k] for k in Adj[node]]
    if (nLabels!=[]):
        Label[node] = maxVote(nLabels)
    else:
        Label[node]=node

However in above code the values assigned to Label, that is the change in dictionary are lost.

Above propagate function is used as callable for MicroThreads (i.e. TaskLets)

© Stack Overflow or respective owner

Related posts about python

Related posts about multithreading