Guest User

Untitled

a guest
Jan 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import multiprocessing as mp
  2.  
  3. def process_data((id,db)):
  4. print 'in processdata'
  5. cursor = db.cursor()
  6. query = ....
  7. #cursor.execute(query)
  8. #....
  9. .....
  10. .....
  11. return row
  12.  
  13. `if __name__ == '__main__':
  14.  
  15. db = getConnection()
  16. cursor = db.cursor()
  17. print 'Initialised db connection and cursor'
  18. inputs = [1,2,3,4,5]
  19. pool = mp.Pool(processes=2)
  20. result_list = pool.map(process_data,zip(inputs,repeat(db)))
  21. #print result_list
  22. pool.close()
  23. pool.join()
  24.  
  25. `Exception in thread Thread-1:
  26. Traceback (most recent call last):
  27. File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner
  28. self.run()
  29. File "/usr/lib/python2.6/threading.py", line 484, in run
  30. self.__target(*self.__args, **self.__kwargs)
  31. File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in _handle_tasks
  32. put(task)
  33. PicklingError: Can't pickle <type 'module'>: attribute lookup __builtin__.module failed`
Add Comment
Please, Sign In to add comment