本文整理汇总了Python中futurist.GreenThreadPoolExecutor方法的典型用法代码示例。如果您正苦于以下问题:Python futurist.GreenThreadPoolExecutor方法的具体用法?Python futurist.GreenThreadPoolExecutor怎么用?Python futurist.GreenThreadPoolExecutor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类futurist
的用法示例。
在下文中一共展示了futurist.GreenThreadPoolExecutor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import futurist [as 别名]
# 或者: from futurist import GreenThreadPoolExecutor [as 别名]
def __init__(self, operation_manager, thread_count=None):
super(ThreadPoolExecutor, self).__init__(operation_manager)
if thread_count is None:
thread_count = CONF.thread_count
self._pool = futurist.GreenThreadPoolExecutor(thread_count)
self._operation_to_run = defaultdict(int)
self._operation_to_cancel = set()
self._lock = RLock()
self._check_functions = {
self._CHECK_ITEMS['is_waiting']: lambda op_id: (
op_id in self._operation_to_run),
self._CHECK_ITEMS['is_canceled']: lambda op_id: (
op_id in self._operation_to_cancel),
}
示例2: get_engine
# 需要导入模块: import futurist [as 别名]
# 或者: from futurist import GreenThreadPoolExecutor [as 别名]
def get_engine(self, flow, **kwargs):
if flow is None:
LOG.error("The flow is None, build it first")
raise exception.InvalidTaskFlowObject(
reason=_("The flow is None"))
executor = kwargs.get('executor', None)
engine = kwargs.get('engine', None)
store = kwargs.get('store', None)
if not executor:
executor = futurist.GreenThreadPoolExecutor()
if not engine:
engine = 'parallel'
flow_engine = engines.load(flow,
executor=executor,
engine=engine,
store=store)
return flow_engine
示例3: get_engine
# 需要导入模块: import futurist [as 别名]
# 或者: from futurist import GreenThreadPoolExecutor [as 别名]
def get_engine(self, flow, **kwargs):
if flow is None:
LOG.error("Flow is None, build it first")
return
executor = kwargs.get('executor', None)
engine = kwargs.get('engine', None)
store = kwargs.get('store', None)
if not executor:
executor = futurist.GreenThreadPoolExecutor()
if not engine:
engine = 'parallel'
flow_engine = engines.load(flow,
executor=executor,
engine=engine,
store=store)
return flow_engine
示例4: default_executor
# 需要导入模块: import futurist [as 别名]
# 或者: from futurist import GreenThreadPoolExecutor [as 别名]
def default_executor():
thread_count = 5
try:
thread_count = CONF['service:worker'].threads
except Exception:
pass
# TODO(mugsie): if (when) we move away from eventlet this may have to
# revert back to ThreadPoolExecutor - this is changing due to
# https://bugs.launchpad.net/bugs/1782647 (eventlet + py37 issues)
return futurist.GreenThreadPoolExecutor(thread_count)
示例5: list_floatingips
# 需要导入模块: import futurist [as 别名]
# 或者: from futurist import GreenThreadPoolExecutor [as 别名]
def list_floatingips(self, context, region=None):
"""
Get floating ips based on the current context from Neutron
"""
endpoints = self._endpoints(
service_catalog=context.service_catalog,
service_type='network',
endpoint_type=CONF['network_api:neutron'].endpoint_type,
config_section='network_api:neutron',
region=region
)
floating_ips = []
with futurist.GreenThreadPoolExecutor(max_workers=5) as executor:
executors = [
executor.submit(
self._get_floating_ips,
context,
endpoint,
region,
project_id=context.project_id
) for endpoint, region in endpoints
]
for future in concurrent.futures.as_completed(executors):
try:
floating_ips.extend(future.result())
except Exception as e:
raise exceptions.NeutronCommunicationFailure(e)
return floating_ips
示例6: __init__
# 需要导入模块: import futurist [as 别名]
# 或者: from futurist import GreenThreadPoolExecutor [as 别名]
def __init__(self, applier_manager):
self.applier_manager = applier_manager
workers = CONF.watcher_applier.workers
self.executor = futurist.GreenThreadPoolExecutor(max_workers=workers)
示例7: __init__
# 需要导入模块: import futurist [as 别名]
# 或者: from futurist import GreenThreadPoolExecutor [as 别名]
def __init__(self, messaging):
self._messaging = messaging
self._executor = futurist.GreenThreadPoolExecutor(
max_workers=CONF.watcher_decision_engine.max_audit_workers)
self._oneshot_handler = o_handler.OneShotAuditHandler()
self._continuous_handler = c_handler.ContinuousAuditHandler().start()
self._event_handler = e_handler.EventAuditHandler()
示例8: __init__
# 需要导入模块: import futurist [as 别名]
# 或者: from futurist import GreenThreadPoolExecutor [as 别名]
def __init__(self):
self.amount_workers = CONF.watcher_decision_engine.max_general_workers
self._threadpool = futurist.GreenThreadPoolExecutor(
max_workers=self.amount_workers)
示例9: __init__
# 需要导入模块: import futurist [as 别名]
# 或者: from futurist import GreenThreadPoolExecutor [as 别名]
def __init__(self, max_workers=10):
pool = futurist.GreenThreadPoolExecutor(int(max_workers))
super(GreenThreadPoolExecutor, self).__init__(pool)
示例10: _create_executor
# 需要导入模块: import futurist [as 别名]
# 或者: from futurist import GreenThreadPoolExecutor [as 别名]
def _create_executor(self, max_workers=None):
if max_workers is None:
max_workers = self.DEFAULT_WORKERS
return futurist.GreenThreadPoolExecutor(max_workers=max_workers)
示例11: _make_engine
# 需要导入模块: import futurist [as 别名]
# 或者: from futurist import GreenThreadPoolExecutor [as 别名]
def _make_engine(self, flow, flow_detail=None, executor=None):
if executor is None:
executor = futurist.GreenThreadPoolExecutor()
self.addCleanup(executor.shutdown)
return taskflow.engines.load(flow,
flow_detail=flow_detail,
backend=self.backend,
engine='parallel',
executor=executor)
示例12: test_green_executor_creation
# 需要导入模块: import futurist [as 别名]
# 或者: from futurist import GreenThreadPoolExecutor [as 别名]
def test_green_executor_creation(self):
with futurist.GreenThreadPoolExecutor(1) as e:
eng = self._create_engine(executor=e)
self.assertIsInstance(eng._task_executor,
executor.ParallelThreadTaskExecutor)
示例13: _make_engine
# 需要导入模块: import futurist [as 别名]
# 或者: from futurist import GreenThreadPoolExecutor [as 别名]
def _make_engine(self, flow, flow_detail=None, executor=None):
if executor is None:
executor = futurist.GreenThreadPoolExecutor()
self.addCleanup(executor.shutdown)
return taskflow.engines.load(flow, flow_detail=flow_detail,
backend=self.backend, engine='parallel',
executor=executor)
示例14: executor
# 需要导入模块: import futurist [as 别名]
# 或者: from futurist import GreenThreadPoolExecutor [as 别名]
def executor():
"""Return the current futures executor."""
global _EXECUTOR
if _EXECUTOR is None:
_EXECUTOR = futurist.GreenThreadPoolExecutor(
max_workers=CONF.max_concurrency)
return _EXECUTOR
示例15: main
# 需要导入模块: import futurist [as 别名]
# 或者: from futurist import GreenThreadPoolExecutor [as 别名]
def main():
if len(sys.argv) == 2:
tbl = []
with open(sys.argv[1], 'rb') as fh:
reader = csv.reader(fh)
for row in reader:
tbl.append([float(r) if r else 0.0 for r in row])
else:
# Make some random table out of thin air...
tbl = []
cols = random.randint(1, 100)
rows = random.randint(1, 100)
for _i in compat_range(0, rows):
row = []
for _j in compat_range(0, cols):
row.append(random.random())
tbl.append(row)
# Generate the work to be done.
f = make_flow(tbl)
# Now run it (using the specified executor)...
try:
executor = futurist.GreenThreadPoolExecutor(max_workers=5)
except RuntimeError:
# No eventlet currently active, use real threads instead.
executor = futurist.ThreadPoolExecutor(max_workers=5)
try:
e = engines.load(f, engine='parallel', executor=executor)
for st in e.run_iter():
print(st)
finally:
executor.shutdown()
# Find the old rows and put them into place...
#
# TODO(harlowja): probably easier just to sort instead of search...
computed_tbl = []
for i in compat_range(0, len(tbl)):
for t in f:
if t.index == i:
computed_tbl.append(e.storage.get(t.name))
# Do some basic validation (which causes the return code of this process
# to be different if things were not as expected...)
if len(computed_tbl) != len(tbl):
return 1
else:
return 0