Monday, May 20, 2013

How to use python (maya) multithreading

How to use python (maya) multithreading

I've been looking at examples from other people but I can't seem to get it to work properly.
It'll either use a single core, or basically freeze up maya if given too much to process, but I never seem to get more than one core working at once.
So for example, this is kind of what I'd like it to do, on a very basic level. Mainly just let each loop run simultaneously on a different processor with the different values (in this case, the two values would use two processors)
mylist = [50, 100, 23]

newvalue = [50,51]

for j in range(0, len(newvalue)):

    exists = False
    for i in range(0, len(mylist)):

        #search list
        if newvalue[j] == mylist[i]:
            exists = True

    #add to list
    if exists == True:
        mylist.append(mylist)
Would it be possible to pull this off? The actual code I'm wanting to use it on can take from a few seconds to like 10 minutes for each loop, but they could theoretically all run at once, so I thought multithreading would speed it up loads
Bear in mind I'm still relatively new to python so an example would be really appreciated
Cheers :)