本文整理汇总了Python中ThreadPool.ThreadPool.startWorking方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadPool.startWorking方法的具体用法?Python ThreadPool.startWorking怎么用?Python ThreadPool.startWorking使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ThreadPool.ThreadPool
的用法示例。
在下文中一共展示了ThreadPool.startWorking方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getWantToSeeMovies
# 需要导入模块: from ThreadPool import ThreadPool [as 别名]
# 或者: from ThreadPool.ThreadPool import startWorking [as 别名]
def getWantToSeeMovies(self):
searchURL = self.baseURL + '/usuario/' + self.username + '/quero-ver/';
moviesVec = []
netflixVec = []
nThreads = 8
threadPool = ThreadPool(nThreads)
threadPool.startWorking()
def parsePage(pageUrl):
wantToSeeCatalogueHTML = urllib.request.urlopen(urllib.request.Request(pageUrl, headers=self.hdr))
catalogueSoup = BeautifulSoup(wantToSeeCatalogueHTML, 'html.parser')
print(pageUrl)
#looping through each movie in the current page
for movieDiv in catalogueSoup.findAll('li', { 'class': 'span2 movie_list_item'}):
divSoup = BeautifulSoup(str(movieDiv), 'html.parser')
moviehref = str(divSoup.find("a")['href'])
print(moviehref)
movieURL = self.baseURL + moviehref
threadPool.putInQueue(parseMovie, {"movieURL": movieURL})
def parseMovie(movieURL):
movie = {}
moviePageHtml = urllib.request.urlopen(urllib.request.Request(movieURL, headers=self.hdr))
moviePageSoup = BeautifulSoup(moviePageHtml, 'html.parser')
movie['name'] = str(moviePageSoup.find('h2',{'class':'movie-original-title'}).string)
movie['duration'] = str(moviePageSoup.find('span',{'class':'running_time'}).string)
print(movie)
moviesVec.append(movie)
threadPool.putInQueue(checkNetflix, {'title': movie['name']})
def checkNetflix(title):
netflixWrapper = NetflixWrapper()
resp = netflixWrapper.isTitleInNetflix(title)
if(resp[0]):
netflixVec.append(resp[1])
for i in range(1, self.getWantToSeePages() + 1):
pageUrl = searchURL + '?pagina=' + str(i)
threadPool.putInQueue(parsePage, {'pageUrl': pageUrl})
#block until all tasks are done
threadPool.end()
return [moviesVec, netflixVec]