Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/python
- from multiprocessing import Pool
- from threading import current_thread
- from multiprocessing.managers import BaseManager
- class FunctionManager(BaseManager):
- pass
- def maFunction(a, b):
- for j in range(0, 10000):
- for k in range(0, 10000):
- for l in range(0, 10000):
- a + b
- class MaClass(object):
- _maFunction = maFunction
- def execute(self, a, b):
- MaClass._maFunction(a, b)
- def threadedFunction(f_i_args):
- print("[" + current_thread().getName() + "] Hello with: " + str(f_i_args))
- (f, i, args) = f_i_args
- f(*args)
- FunctionManager.register('MaClass', MaClass)
- myManager = FunctionManager()
- myManager.start()
- instance = myManager.MaClass()
- p = Pool()
- args = []
- for i in range(1000):
- args.append([instance.execute, i, (i, 2)])
- p.map(threadedFunction, args) # Does not work
- p.close()
- p.join()
- myManager.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement