I'm trying to run multiple instances of a selenium webdriver in a unittest. I came across this post concerning threading: Python multithreading for dummies
It seems like I'd be able to implement the map function since my main runTest method just iterates over some database rows while using the webdriver to visit a page and verify data from the database. How can I pass a unique webdriver instance to each worker though?
import urllib2
from multiprocessing.dummy import Pool as ThreadPool
urls = [
'http://www.python.org',
'http://ift.tt/Uac8wQ',
'http://ift.tt/1IbyHGu',
'http://ift.tt/1maEdNN',
'http://ift.tt/sY1R1N',
'http://ift.tt/So7VCZ',
'http://ift.tt/1IbyGCu',
'http://ift.tt/1iu7Zh8',
]
# Make the Pool of workers
pool = ThreadPool(4)
I'd like to be able just do something like this:
# Open the urls in their own threads and return the results
results = pool.map(urllib2.urlopen, UNIQUE_WEBDRIVER_INSTANCE, urls)
#close the pool and wait for the work to finish
pool.close()
pool.join()
Aucun commentaire:
Enregistrer un commentaire