本文整理汇总了Python中asyncio.locks方法的典型用法代码示例。如果您正苦于以下问题:Python asyncio.locks方法的具体用法?Python asyncio.locks怎么用?Python asyncio.locks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asyncio
的用法示例。
在下文中一共展示了asyncio.locks方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import locks [as 别名]
def __init__(self, log,
roots, exclude=None, strict=True, # What to crawl.
max_redirect=10, max_tries=4, # Per-url limits.
max_tasks=10, max_pool=10, # Global limits.
):
self.log = log
self.roots = roots
self.exclude = exclude
self.strict = strict
self.max_redirect = max_redirect
self.max_tries = max_tries
self.max_tasks = max_tasks
self.max_pool = max_pool
self.todo = {}
self.busy = {}
self.done = {}
self.pool = ConnectionPool(self.log, max_pool, max_tasks)
self.root_domains = set()
for root in roots:
parts = urllib.parse.urlparse(root)
host, port = urllib.parse.splitport(parts.netloc)
if not host:
continue
if re.match(r'\A[\d\.]*\Z', host):
self.root_domains.add(host)
else:
host = host.lower()
if self.strict:
self.root_domains.add(host)
if host.startswith('www.'):
self.root_domains.add(host[4:])
else:
self.root_domains.add('www.' + host)
else:
parts = host.split('.')
if len(parts) > 2:
host = '.'.join(parts[-2:])
self.root_domains.add(host)
for root in roots:
self.add_url(root)
self.governor = asyncio.locks.Semaphore(max_tasks)
self.termination = asyncio.locks.Condition()
self.t0 = time.time()
self.t1 = None