Spaces:
Sleeping
Sleeping
File size: 1,258 Bytes
5ff89f7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import multiprocessing
from Jumia_scraper import scrape_jumia
from Amazon_scraper import scrape_amazon
import time
def scrape_product_multiprocessing(product_name,your_cost):
queue = multiprocessing.Queue()
# Create processes
p1 = multiprocessing.Process(target=scrape_amazon, args=(product_name, your_cost, queue))
p2 = multiprocessing.Process(target=scrape_jumia, args=(product_name, your_cost, queue))
# Start processes
p1.start()
p2.start()
# Wait for processes to complete
p1.join()
p2.join()
# Debugging: Check the queue size after processes finish
print(f"Queue size after both processes finish: {queue.qsize()}")
# Retrieve results from queue
results_amazon = []
results_jumia = []
# Check if queue has results
while not queue.empty():
try:
site, results = queue.get()
# print(f"Results from {site}: {results}") # Debugging output
if site == 'amazon':
results_amazon = results
elif site == 'jumia':
results_jumia = results
except Exception as e:
print(e)
# Return results and total time
return results_amazon, results_jumia |