I want to run two functions in parallel. These functions are executed many times in a loop. Here is my code:
#get the html content of the first rental
previous_url_rental=BeautifulSoup(urllib.urlopen(rentals[0]))
#for each rental on the page
for rental_num in xrange(1, len(rentals)):
#get the html content of the page
url_rental=BeautifulSoup(urllib.urlopen(rentals[rental_num]))
#get and save the rental data in the csv file
writer.writerow(get_data_rental(previous_url_rental))
previous_url_rental=url_rental
#save last rental
writer.writerow(get_data_rental(previous_url_rental))
There are two main things:
1/ get the html content of a page:
url_rental=BeautifulSoup(urllib.urlopen(rentals[rental_num]))
2/ retrieve and save data from the html content of the previous page (and not the current page because these 2 processes would be dependent):
writer.writerow(get_data_rental(previous_url_rental))
I would like to run these two lines in parallel: a first process would get the html content of the page n+1
while a second process would retrieve and save the data of the page n
.
I have searched and found this post so far: Python: How can I run python functions in parallel?. But I don't understand how to use it!
Thank you for your time.