Skip to content Skip to sidebar Skip to footer

How To Write The Map Sentence Here To Call Array To Calculate With Threadpool Module?

I want to make a practice with module ThreadPool,to add 2 for every element in range(1,100). from multiprocessing.pool import ThreadPool array=range(1,100) class test(): def m

Solution 1:

If you're going to make myadd an instance method of the test class, you have to actually instantiate the test class to call myadd:

from multiprocessing.pool import ThreadPool

class test():
    def myadd(self,x):
        return(x+2)

t = ThreadPool(5)
test_obj = test()  # This gives you an instance of the `test` class
t.map(test_obj.my_add, range(1,100))  # Now you can call `myadd` on your instance

Post a Comment for "How To Write The Map Sentence Here To Call Array To Calculate With Threadpool Module?"