Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. import MySQLdb
  2. from multiprocessing import Pool
  3.  
  4. def some_math(x, y):
  5. f(x[1], x[2], y[1], y[2])
  6. return f
  7.  
  8. def distance(x):
  9. x_distances = []
  10. for y in all_y:
  11. distance = some_math(x, y)
  12. if distance > 1000000:
  13. continue
  14. else:
  15. x_distances.append(x[0], y[0],distance)
  16. mysql.executemany(sql_update, x_distances)
  17. mydb.commit()
  18.  
  19. all_x = []
  20. all_y = []
  21. sql_x = 'SELECT id, lat, lng FROM table'
  22. sql_y = 'SELECT id, lat, lng FROM table'
  23. sql_update = 'INSERT INTO distances (id_x, id_y, distance) VALUES (%s, %s, %S)'
  24.  
  25. cursor.execute(sql_x)
  26. all_x = cursor.fetchall()
  27.  
  28. cursor.execute(sql_y)
  29. all_y = cursor.fetchall()
  30.  
  31. p = Pool(4)
  32. for x in all_x:
  33. p.apply_async(distance, x)
  34.  
  35. p = Pool(4)
  36. for x in all_x:
  37. p.map(distance, x)
  38.  
  39. Traceback (most recent call last):
  40. File "./distance-house.py", line 94, in <module>
  41. p.map(range, row)
  42. File "/usr/lib/python2.7/multiprocessing/pool.py", line 251, in map
  43. return self.map_async(func, iterable, chunksize).get()
  44. File "/usr/lib/python2.7/multiprocessing/pool.py", line 558, in get
  45. raise self._value
  46. TypeError: 'float' object has no attribute '__getitem__'
  47.  
  48. p = Pool(4)
  49. p.map(distance, all_x)
  50.  
  51. def Add(z):
  52. x,y = z
  53. return x + y
  54.  
  55. a = [ 0 , 1, 2, 3]
  56. b = [ 5, 6, 7, 8]
  57. ab = (a,b)
  58.  
  59. Add(ab)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement