2 つの関数を並行して実行したい。これらの関数は、ループ内で何度も実行されます。これが私のコードです:
#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))
次の 2 つの主な事項があります。
1/ ページの HTML コンテンツを取得します。
url_rental=BeautifulSoup(urllib.urlopen(rentals[rental_num]))
2/ 前のページの html コンテンツからデータを取得して保存します (これら 2 つのプロセスが依存するため、現在のページではありません)。
writer.writerow(get_data_rental(previous_url_rental))
これらの 2 行を並行して実行したいと思います。最初のプロセスはページの html コンテンツをn+1
取得し、2 番目のプロセスはページのデータを取得して保存しますn
。これまでにこの投稿を検索して見つけました: Python: How can I run python functions in parallel? . でも使い方がわからない!
お時間をいただきありがとうございます。