当前位置: 首页>>代码示例>>Python>>正文


Python ThreadPool.end方法代码示例

本文整理汇总了Python中ThreadPool.ThreadPool.end方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadPool.end方法的具体用法?Python ThreadPool.end怎么用?Python ThreadPool.end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ThreadPool.ThreadPool的用法示例。


在下文中一共展示了ThreadPool.end方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getWantToSeeMovies

# 需要导入模块: from ThreadPool import ThreadPool [as 别名]
# 或者: from ThreadPool.ThreadPool import end [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]
开发者ID:LucasIME,项目名称:FilmowParser,代码行数:49,代码来源:FilmowParser.py


注:本文中的ThreadPool.ThreadPool.end方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。