本文整理汇总了Python中gevent.threadpool.ThreadPool方法的典型用法代码示例。如果您正苦于以下问题:Python threadpool.ThreadPool方法的具体用法?Python threadpool.ThreadPool怎么用?Python threadpool.ThreadPool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gevent.threadpool
的用法示例。
在下文中一共展示了threadpool.ThreadPool方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from gevent import threadpool [as 别名]
# 或者: from gevent.threadpool import ThreadPool [as 别名]
def __init__(self, k8s_config=None, k8s_namespace=None, label_selector=None):
from kubernetes import config, client
from gevent.threadpool import ThreadPool
if k8s_config is not None:
self._k8s_config = k8s_config
elif os.environ.get('KUBE_API_ADDRESS'):
self._k8s_config = client.Configuration()
self._k8s_config.host = os.environ['KUBE_API_ADDRESS']
else:
self._k8s_config = config.load_incluster_config()
self._k8s_namespace = k8s_namespace or os.environ.get('MARS_K8S_POD_NAMESPACE') or 'default'
self._label_selector = label_selector
self._client = client.CoreV1Api(client.ApiClient(self._k8s_config))
self._pool = ThreadPool(1)
self._pod_to_ep = None
示例2: _get_messages
# 需要导入模块: from gevent import threadpool [as 别名]
# 或者: from gevent.threadpool import ThreadPool [as 别名]
def _get_messages(self):
# Emulate batch messages by polling rabbitmq server multiple times
pool = ThreadPool(settings.POLLER_CONFIG['batchsize'])
for i in range(settings.POLLER_CONFIG['batchsize']):
if settings.QUEUE_TYPE in ['SQS', 'sqs']:
pool.spawn(self._get_sqs_messages)
elif settings.QUEUE_TYPE in ['RABBITMQ', 'rabbitmq']:
pool.spawn(self._get_rabbitmq_messages,i)
else:
raise ValueError('Incorrect value "%s" for QUEUE_TYPE in %s' %
(settings.QUEUE_TYPE, settings.SETTINGS_MODULE))
示例3: _admin_init
# 需要导入模块: from gevent import threadpool [as 别名]
# 或者: from gevent.threadpool import ThreadPool [as 别名]
def _admin_init(self):
if self.coll_dir:
self.load_coll_dir()
if self.inputs:
if self.load_cache():
return
pool = ThreadPool(maxsize=1)
pool.spawn(self.safe_auto_load_warcs)
示例4: __init__
# 需要导入模块: from gevent import threadpool [as 别名]
# 或者: from gevent.threadpool import ThreadPool [as 别名]
def __init__(self, **kwargs):
"""
"""
super().__init__(**kwargs)
self.component_rule = {}
self.whitelist_rule = {}
self.blacklist_rule = {}
self._grep = GrepCMD()
self._key = 1
self.sonarqube = None
self.pool = ThreadPool(20)
示例5: start_blacklist
# 需要导入模块: from gevent import threadpool [as 别名]
# 或者: from gevent.threadpool import ThreadPool [as 别名]
def start_blacklist(self, project):
"""
:param project:
:return:
"""
def __scan(file_path):
for rule in self.blacklist_rule:
flag, _ = rule.verify(reference_value=file_path)
project.logger.debug("[RuleScanner] rule: [{0}], file: [{1}]".format(rule, file_path))
if flag:
relative_path = file_path.replace(project.scan_path, "")
project.logger.info("[RuleScanner] [Blacklist] [+] Found '{0}' vulnerability in '{1}' file.".format(rule.name, relative_path))
info = rule.get_info(match_content=_, origin_file=file_path)
if project.web_url:
report = '{0}/blob/{1}{2}#L{3}'.format(
project.web_url,
project.branch,
relative_path,
info['start_line']
)
else:
report = ''
author, author_email = get_git_author(project.get_last_author(file_path))
vuln = Vulnerability(
task_id=project.task_id,
rule_key=rule.key,
risk_id=rule.risk_id,
title=rule.name,
file=relative_path,
author=author,
author_email=author_email,
hash=project.get_last_commit(),
start_line=info['start_line'],
end_line=info['end_line'],
report=report,
code_example=info['code_example'],
evidence_content=_,
engine=self.key,
)
vuln_key = hash_md5('{0}_{1}_{2}'.format(file_path, rule.id, info['start_line']))
if vuln_key not in kb.result[project.key]:
kb.result[project.key][vuln_key] = vuln.info
project.logger.debug('[RuleScanner] {0}'.format(vuln))
project.logger.info("[RuleScanner] Begin to perform rule-based blacklist vulnerability analysis...")
pool = ThreadPool(project.threads or 20)
for fpath, dirs, fs in os.walk(project.scan_path):
for f in fs:
pool.spawn(__scan, os.path.join(fpath, f))
gevent.wait()
project.logger.info("[RuleScanner] Rule blacklist scan completed.")
示例6: start_blacklist
# 需要导入模块: from gevent import threadpool [as 别名]
# 或者: from gevent.threadpool import ThreadPool [as 别名]
def start_blacklist(self, project):
"""
:param project:
:return:
"""
def __scan(file_path):
for rule in self.blacklist_rule:
flag = rule.verify(file_path)
if flag:
rule.get_info(file_path)
if project.web_url:
report = '{0}/blob/{1}/{2}#L{3}'.format(
project.web_url,
project.branch,
file_path,
rule.start_line
)
else:
report = ''
author, author_email = get_git_author(project.get_last_author(file_path))
vuln = Vulnerability(
task_id=project.task_id,
rule_key=rule.key,
risk_id=rule.risk_id,
title=rule.name,
file=file_path,
author=author,
author_email=author_email,
hash=project.get_last_commit(),
start_line=rule.start_line,
end_line=rule.end_line,
report=report,
code_example=rule.code_example,
engine=self.key,
)
vuln_key = hash_md5('{0}_{1}_{2}'.format(file_path, rule.id, rule.start_line))
if vuln_key not in kb.result[project.key]:
kb.result[project.key][vuln_key] = vuln.info
project.logger.debug('[PluginScanner] {0}'.format(vuln))
pool = ThreadPool(project.threads)
for fpath, dirs, fs in os.walk(project.scan_path):
for f in fs:
pool.spawn(__scan, os.path.join(fpath, f))
gevent.wait()