/usr/lib/python2.7/dist-packages/cl/results.py is in python-cl 0.0.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | """cl.result"""
from __future__ import absolute_import
from __future__ import with_statement
from kombu.pools import producers
from .exceptions import clError, NoReplyError
__all__ = ["AsyncResult"]
class AsyncResult(object):
Error = clError
NoReplyError = NoReplyError
def __init__(self, ticket, actor):
self.ticket = ticket
self.actor = actor
def _first(self, replies):
if replies is not None:
replies = list(replies)
if replies:
return replies[0]
raise self.NoReplyError("No reply received within time constraint")
def get(self, **kwargs):
return self._first(self.gather(**dict(kwargs, limit=1)))
def gather(self, propagate=True, **kwargs):
connection = self.actor.connection
gather = self._gather
with producers[connection].acquire(block=True) as producer:
for r in gather(producer.connection, producer.channel, self.ticket,
propagate=propagate, **kwargs):
yield r
def _gather(self, *args, **kwargs):
propagate = kwargs.pop("propagate", True)
return (self.to_python(reply, propagate=propagate)
for reply in self.actor._collect_replies(*args, **kwargs))
def to_python(self, reply, propagate=True):
try:
return reply["ok"]
except KeyError:
error = self.Error(*reply.get("nok") or ())
if propagate:
raise error
return error
|