コード例 #1
0
ファイル: _rfoo.py プロジェクト: dirkakrid/rfoo
    def _dispatch(self, handler, conn, n=1000):
        """Serve single call."""

        for i in range(n):
            data = conn.read()
            type, name, args, kwargs = loads(data)

            try:
                foo = handler._methods.get(name,
                                           None) or handler._get_method(name)
                result = foo(*args, **kwargs)
                error = None

            except Exception:
                logging.debug('Caught exception raised by callable.',
                              exc_info=True)
                # Use exc_info for py2.x py3.x compatibility.
                t, v, tb = sys.exc_info()
                if t in BUILTIN_EXCEPTIONS:
                    error = (t.__name__, v.args)
                else:
                    error = (repr(t), v.args)
                result = None

            if type == CALL:
                response = dumps((result, error))
                conn.write(response)
コード例 #2
0
ファイル: _rfoo.py プロジェクト: dirkakrid/rfoo
    def __call__(self, *args, **kwargs):
        """Call method on server."""

        data = dumps((CALL, self._name, args, kwargs))
        self._conn.write(data)

        response = self._conn.read()
        value, error = loads(response)

        if error is None:
            return value

        try:
            name, args = error
        except TypeError:
            # Handle old way of returning error as repr.
            logging.warning('Unknown error returned by proxy, error=%s.',
                            error)
            raise ServerError(error)

        logging.warning('Error returned by proxy, name=%s, args=%s.', name,
                        args)

        # Raise built-in exceptions sent by server.
        if name in BUILTIN_EXCEPTIONS_NAMES:
            e = getattr(builtins, name)()
            e.args = args
            raise e  # Exception sent from server. Original traceback unavailable.

        self._on_exception(name, args)
コード例 #3
0
ファイル: _rfoo.py プロジェクト: wwoods/rfooConsoleUtil
    def _dispatch(self, handler, conn, n=1000):
        """Serve single call."""

        for i in range(n):
            data = conn.read()
            type, name, args, kwargs = loads(data)

            try:    
                foo = handler._methods.get(name, None) or handler._get_method(name)
                result = foo(*args, **kwargs)
                error = None

            except Exception:
                logging.debug('Caught exception raised by callable.', exc_info=True)
                # Use exc_info for py2.x py3.x compatibility.
                t, v, tb = sys.exc_info()
                if t in BUILTIN_EXCEPTIONS:
                    error = (t.__name__, v.args)
                else:
                    error = (repr(t), v.args)
                result = None

            if type == CALL:
                response = dumps((result, error))
                conn.write(response)
コード例 #4
0
ファイル: _rfoo.py プロジェクト: wwoods/rfooConsoleUtil
    def __call__(self, *args, **kwargs):
        """Call method on server."""
       
        data = dumps((CALL, self._name, args, kwargs))
        self._conn.write(data)
        
        response = self._conn.read()
        value, error = loads(response)
        
        if error is None:
            return value

        try:
            name, args = error
        except TypeError:
            # Handle old way of returning error as repr.
            logging.warning('Unknown error returned by proxy, error=%s.', error)
            raise ServerError(error)

        logging.warning('Error returned by proxy, name=%s, args=%s.', name, args)

        # Raise built-in exceptions sent by server.
        if name in BUILTIN_EXCEPTIONS_NAMES:
            e = getattr(builtins, name)()
            e.args = args
            raise e # Exception sent from server. Original traceback unavailable.

        self._on_exception(name, args)
コード例 #5
0
ファイル: talk.py プロジェクト: wwoods/lamegame_tasking
 def getObjs(self, key):
     msg = self.c.basic_get(queue = key, no_ack = True)
     if msg[2] is not None:
         return pickle.loads(msg[2])
     return []
コード例 #6
0
ファイル: talk.py プロジェクト: wwoods/lamegame_tasking
 def getObjs(self, key):
     o = self._redis.rpop(key)
     if o is None:
         return []
     o = pickle.loads(o)
     return o