本文整理汇总了Python中celery.result.ResultSet.iter_native方法的典型用法代码示例。如果您正苦于以下问题:Python ResultSet.iter_native方法的具体用法?Python ResultSet.iter_native怎么用?Python ResultSet.iter_native使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类celery.result.ResultSet
的用法示例。
在下文中一共展示了ResultSet.iter_native方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: aggregate_result_set
# 需要导入模块: from celery.result import ResultSet [as 别名]
# 或者: from celery.result.ResultSet import iter_native [as 别名]
def aggregate_result_set(self, agg, acc):
"""
Loop on a set of celery AsyncResults and update the accumulator
by using the aggregation function.
:param agg: the aggregation function, (acc, val) -> new acc
:param acc: the initial value of the accumulator
:returns: the final value of the accumulator
"""
if not self.results:
return acc
backend = current_app().backend
amqp_backend = backend.__class__.__name__.startswith("AMQP")
rset = ResultSet(self.results)
for task_id, result_dict in rset.iter_native():
check_mem_usage() # warn if too much memory is used
result = result_dict["result"]
if isinstance(result, BaseException):
raise result
self.received.append(len(result))
acc = agg(acc, result.unpickle())
if amqp_backend:
# work around a celery bug
del backend._cache[task_id]
return acc
示例2: aggregate_result_set
# 需要导入模块: from celery.result import ResultSet [as 别名]
# 或者: from celery.result.ResultSet import iter_native [as 别名]
def aggregate_result_set(self, agg, acc):
"""
Loop on a set of celery AsyncResults and update the accumulator
by using the aggregation function.
:param agg: the aggregation function, (acc, val) -> new acc
:param acc: the initial value of the accumulator
:returns: the final value of the accumulator
"""
if isinstance(self.oqtask, types.FunctionType):
# don't use celery
return super(OqTaskManager, self).aggregate_result_set(
agg, acc)
if not self.results:
return acc
backend = current_app().backend
amqp_backend = backend.__class__.__name__.startswith('AMQP')
rset = ResultSet(self.results)
for task_id, result_dict in rset.iter_native():
idx = self.task_ids.index(task_id)
self.task_ids.pop(idx)
parallel.check_mem_usage() # warn if too much memory is used
result = result_dict['result']
if isinstance(result, BaseException):
raise result
self.received.append(len(result))
acc = agg(acc, result.unpickle())
if amqp_backend:
# work around a celery bug
del backend._cache[task_id]
return acc
示例3: aggregate_result_set
# 需要导入模块: from celery.result import ResultSet [as 别名]
# 或者: from celery.result.ResultSet import iter_native [as 别名]
def aggregate_result_set(self, agg, acc):
"""
Loop on a set results and update the accumulator
by using the aggregation function.
:param agg: the aggregation function, (acc, val) -> new acc
:param acc: the initial value of the accumulator
:returns: the final value of the accumulator
"""
if not self.results:
return acc
distribute = oq_distribute() # not called for distribute == 'no'
if distribute == 'celery':
backend = current_app().backend
amqp_backend = backend.__class__.__name__.startswith('AMQP')
rset = ResultSet(self.results)
for task_id, result_dict in rset.iter_native():
idx = self.task_ids.index(task_id)
self.task_ids.pop(idx)
check_mem_usage() # warn if too much memory is used
result = result_dict['result']
if isinstance(result, BaseException):
raise result
self.received.append(len(result))
acc = agg(acc, result.unpickle())
if amqp_backend:
# work around a celery bug
del backend._cache[task_id]
return acc
elif distribute == 'futures':
for future in as_completed(self.results):
check_mem_usage()
# log a warning if too much memory is used
result = future.result()
if isinstance(result, BaseException):
raise result
self.received.append(len(result))
acc = agg(acc, result.unpickle())
return acc
示例4: aggregate_result_set
# 需要导入模块: from celery.result import ResultSet [as 别名]
# 或者: from celery.result.ResultSet import iter_native [as 别名]
def aggregate_result_set(self, agg, acc):
"""
Loop on a set of celery AsyncResults and update the accumulator
by using the aggregation function.
:param agg: the aggregation function, (acc, val) -> new acc
:param acc: the initial value of the accumulator
:returns: the final value of the accumulator
"""
if not self.results:
return acc
backend = current_app().backend
rset = ResultSet(self.results)
for task_id, result_dict in rset.iter_native():
check_mem_usage() # log a warning if too much memory is used
result = result_dict['result']
if isinstance(result, BaseException):
raise result
acc = agg(acc, result.unpickle())
del backend._cache[task_id] # work around a celery bug
return acc