Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import MySQLdb
- from multiprocessing import Pool
- def some_math(x, y):
- f(x[1], x[2], y[1], y[2])
- return f
- def distance(x):
- x_distances = []
- for y in all_y:
- distance = some_math(x, y)
- if distance > 1000000:
- continue
- else:
- x_distances.append(x[0], y[0],distance)
- mysql.executemany(sql_update, x_distances)
- mydb.commit()
- all_x = []
- all_y = []
- sql_x = 'SELECT id, lat, lng FROM table'
- sql_y = 'SELECT id, lat, lng FROM table'
- sql_update = 'INSERT INTO distances (id_x, id_y, distance) VALUES (%s, %s, %S)'
- cursor.execute(sql_x)
- all_x = cursor.fetchall()
- cursor.execute(sql_y)
- all_y = cursor.fetchall()
- p = Pool(4)
- for x in all_x:
- p.apply_async(distance, x)
- p = Pool(4)
- for x in all_x:
- p.map(distance, x)
- Traceback (most recent call last):
- File "./distance-house.py", line 94, in <module>
- p.map(range, row)
- File "/usr/lib/python2.7/multiprocessing/pool.py", line 251, in map
- return self.map_async(func, iterable, chunksize).get()
- File "/usr/lib/python2.7/multiprocessing/pool.py", line 558, in get
- raise self._value
- TypeError: 'float' object has no attribute '__getitem__'
- p = Pool(4)
- p.map(distance, all_x)
- def Add(z):
- x,y = z
- return x + y
- a = [ 0 , 1, 2, 3]
- b = [ 5, 6, 7, 8]
- ab = (a,b)
- Add(ab)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement