Skip to content

Instantly share code, notes, and snippets.

@AbdouSeck
Created July 14, 2021 00:08
Show Gist options
  • Save AbdouSeck/8d70a05891d0c7079126cd9d571f9b01 to your computer and use it in GitHub Desktop.
Save AbdouSeck/8d70a05891d0c7079126cd9d571f9b01 to your computer and use it in GitHub Desktop.
Using mp.Pool instead of mp.Process
import multiprocessing as mp
def RunPrice(items, price):
print("There is %s items, price is: %s" % (items, price))
def GetTargetItemsAndPrice(cursor):
res = cursor.execute("SELECT DISTINCT items, price FROM SELLS")
results = dict()
with mp.Pool() as pool:
for row in res.fetchall():
args = (row[0], row[1])
results[args] = pool.apply_async(RunPrice, args=args)
for result in results.values():
result.get()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment