本文整理汇总了Python中multiprocessing.Pool._terminate方法的典型用法代码示例。如果您正苦于以下问题:Python Pool._terminate方法的具体用法?Python Pool._terminate怎么用?Python Pool._terminate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.Pool
的用法示例。
在下文中一共展示了Pool._terminate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_new_talks
# 需要导入模块: from multiprocessing import Pool [as 别名]
# 或者: from multiprocessing.Pool import _terminate [as 别名]
def get_new_talks(self):
"""
Returns talks as dicts {title:, author:, thumb:, date:, duration:, link:}.
"""
sd_rss_url = "http://feeds.feedburner.com/tedtalks_video"
hd_rss_url = "http://feeds.feedburner.com/TedtalksHD"
rss_urls = [sd_rss_url, hd_rss_url] # Prefer HD, but get SD if that's all there is (my friends)
document_fetchers = []
if do_multi_threading:
pool = Pool(processes=1) # Maybe it would be better to fetch them simultaneously?
for url in rss_urls:
result = pool.apply_async(get_document, [url])
document_fetchers.append(lambda x: result.get(30))
else:
for url in rss_urls:
document_fetchers.append(lambda x: get_document(url))
talksByTitle = {}
for documentFetcher in document_fetchers:
rss = documentFetcher(None) # Is this evil? We have to pass something into the lambda.
for item in fromstring(rss).findall('channel/item'):
talk = self.get_talk_details(item)
talksByTitle[talk['title']] = talk
if do_multi_threading:
# pool.close()
# pool.join()
# If I close Pool using close/join, then it logs
# ERROR: Error Type: <type 'exceptions.OSError'>
# ERROR: Error Contents: [Errno 3] No such process
# when the app exits (i.e. finalization occurs).
# Whereas this seems to be OK.
pool._terminate()
return talksByTitle.itervalues()