Kjako

worker.py

Apr 13th, 2021
382
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from multiprocessing.managers import BaseManager
  2. from multiprocessing import Pool
  3. import multiprocessing as mp
  4. import sys
  5.  
  6. class QueueManager(BaseManager):
  7.     pass
  8.  
  9. ip = sys.argv[1] if len(sys.argv) > 1 else 'localhost'
  10. port = int(sys.argv[2]) if len(sys.argv) > 2 else 50000
  11.  
  12. QueueManager.register('in_queue')
  13. QueueManager.register('out_queue')
  14. m = QueueManager(address=(ip, port), authkey='blah'.encode())
  15. m.connect()
  16. out_queue = m.out_queue()
  17. in_queue = m.in_queue()
  18.  
  19. def mul(i):
  20.     s = 0
  21.     for j in range(cols):
  22.         s+=A[i][j] * X[j][0]
  23.     result[i] = s
  24.  
  25. while not in_queue.empty():
  26.     [A, X, tasks_number] = in_queue.get()
  27.     rows = len(A)
  28.     cols = len(X)
  29.     result = [0] * (tasks_number[1] - tasks_number[0])
  30.     with Pool(mp.cpu_count()) as p:
  31.         for i in range(tasks_number[1] - tasks_number[0]):
  32.             mul(i)    
  33.     out_queue.put([result, tasks_number])        
  34.     in_queue.task_done()
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×