本文整理汇总了Python中threadpool.ThreadPool.initPool方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadPool.initPool方法的具体用法?Python ThreadPool.initPool怎么用?Python ThreadPool.initPool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类threadpool.ThreadPool
的用法示例。
在下文中一共展示了ThreadPool.initPool方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from threadpool import ThreadPool [as 别名]
# 或者: from threadpool.ThreadPool import initPool [as 别名]
class Spider:
def __init__(self, depth=2):
self.threadPool = ThreadPool(10)
self.depth = depth
def start(self, currentLevel, url):
self.threadPool.initPool()
self.threadPool.putTask(self.crawlPage, \
currentLevel = currentLevel, \
url = url)
def crawlPage(self, args):
print 'crawlPage', args
currentLevel = args['currentLevel']
url = args['url']
req = urllib2.Request(url=url, headers=header)
try:
resp = urllib2.urlopen(req, timeout=10)
except urllib2.HTTPError as e:
# XXX The except HTTPError must come first
# otherwise except URLError will also catch an HTTPError
pass
except urllib2.URLError as e:
pass
except Exception, e:
print e
else: