0
セレンとマルチプロセッシングを使って4つの異なるWebサイトを作成しています。ドライバが生成したWebサイト固有の機能を実行したいと思います。Pythonでマルチプロセッシング中にプール固有の関数を使用するにはどうすればいいですか?
これは私の現在のコードのようになります。
from multiprocessing import Pool
from selenium import webdriver
def gh(hosts):
driver = webdriver.Chrome(executable_path='./chromedriver')
driver.get(hosts)
html_source = driver.page_source
if 'ryan' in html_source:
print 'ryan'
doSomethingForRyan()
elif 'austin' in html_source:
print 'austin'
doSomethingForAustin()
elif 'travis' in html_source:
print 'travis'
doSomethingForTravis()
elif 'levi' in html_source:
print 'levi'
doSomethingForLevi()
else:
print '--NONE--'
if __name__ == '__main__':
p = Pool(4)
hosts = ["http://ryan.com", "https://www.austin.com", "http://levi.com", "http://travis.com"]
p.map(gh, hosts)
私は取得していた結果のようなものです: オースティン オースティン ライアン オースティン
簡単な用語:1つのプールで4人の作業者を実行しています。 – tdelaney
異なるプールで異なる機能を実行するにはどうしたらいいですか? – AlwaysSunny
最低でも、結果を列挙してワーカーが起きているかどうかを確認してください。結果はp.map(gh、hosts):print(result)にあります。作業者は成功/失敗に対してTrue/Falseを返すことができ、失敗した場合は例外が発生します。 – tdelaney