Advertisement
Guest User

multiprocessing

a guest
Apr 25th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import time
  2. from multiprocessing import Process,Queue,current_process
  3. import _pickle as pickle
  4.  
  5.  
  6.  
  7.  
  8.  
  9. def dataRead(queue,fileName):
  10.  
  11.  
  12.  
  13. proc_name = current_process().name
  14. print('{}.pkl'.format(fileName),proc_name,time.time(),'...Start')
  15.  
  16. with open('{}.pkl'.format(fileName), 'rb') as file:
  17. data = pickle.load(file )
  18. file.close()
  19.  
  20.  
  21. print('{}.pkl'.format(fileName),proc_name,time.time(),'...finish')
  22.  
  23.  
  24. queue.put((fileName,data))
  25. print('puts : ',fileName)
  26.  
  27.  
  28.  
  29.  
  30. if __name__ == '__main__':
  31.  
  32. fileNameList = ['userUserSimilarity','topNeighborsIndexNumber','ratings_diff','mean_user_item','indexToFeature']
  33.  
  34. queue = Queue()
  35. processes = []
  36. for filename in fileNameList:
  37. p = Process(target=dataRead,args=(queue,filename))
  38. processes.append(p)
  39. p.start()
  40.  
  41.  
  42.  
  43.  
  44. for p in processes:
  45. listName,listValue = queue.get()
  46. globals()[listName] = listValue
  47. print('*'*10,p,listName)
  48.  
  49. for p in processes:
  50. p.join()
  51. print('*'*7,p)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement