Python multiprocessing instead of threading

I did some tests to check how much speed i can gain with the .NET threading librarys in Ironpython.
The results were far from good:
long list with some Vector3d Multiplication

threading sequence in list: 12121212
        same list access: read + write 
        vectorTask:  1 threads   5.580 sec
        vectorTask:  2 threads   3.890 sec
        vectorTask:  4 threads   3.042 sec
        
        same list access: read only
        vectorTask:  1 threads   4.420 sec
        vectorTask:  2 threads   2.569 sec
        vectorTask:  4 threads   1.879 sec

        2 lists: one read, one write
        vectorTask:  1 threads   5.650 sec
        vectorTask:  2 threads   4.270 sec
        vectorTask:  4 threads   3.238 sec

Now i would like to use the multiprocessing module, as stackoverflow and others suggest, and came to this site:
http://www.ironpython.info/index.php?title=Using_the_Python_Standard_Library

but i have no idea what version of ironpython is running in rhino, and if this would work at all?

Multi-processing uses separate processes instead of separate threads in a single process. This won’t really work in the context of Rhino.

Since I don’t see your sample script I can’t really comment on possibilities for improvement. Care to share your sample?

i see… but maybe i do something else wrong -
here is the test script i wrote (just one list, read + write)

import Rhino
import System
import time
import rhinoscriptsyntax as rs

from Rhino import RhinoApp
from scriptcontext import doc
from System.Threading import Thread, ThreadStart, ParameterizedThreadStart



def RunCommand():
    RhinoApp.ClearCommandHistoryWindow()
    print("****************************")
    
    iter = 5000000    # number of operations
    vec = [Rhino.Geometry.Vector3d(1,1,1)] * iter    # populate the list

    thread = []        # threads
    threadnum = 4    # number of threads
    
    def vectorTask(id):
        # the xrange jumps in steps of threadnum,
        # i thought that it could be faster by chunking the tasks
        # instead of jumping through the list (read somewhere about branch prediction)
        # but didnt help either
        for i in xrange(id,iter,threadnum):
            vec[i] = Rhino.Geometry.Vector3d.Multiply(1.234, vec[i])
    
    start = time.time()
    for i in xrange(0,threadnum):
        thread.append(Thread(ParameterizedThreadStart(vectorTask)))
    for i in xrange(0,threadnum):
        thread[i].Start(i)
    for i in xrange(0,threadnum):
        thread[i].Join()
    
    print("vectorTask:  "+str(threadnum)+" threads   "+str(time.time()-start)[:5]+ " sec"); doc.Views.Redraw(); RhinoApp.Wait()

if __name__ == "__main__":
    RunCommand()
1 Like