Example #1
0
    def __call__(self, method, *args, **kargs):
        # We modify zerorpc's __call__ method to remove the heartbeat feature since it may cause server-side requests
        # to get interrupted during processing if it detects a lost remote and it may also fail if the client and
        # server don't have the same heartbeat frequency set.
        #
        # The following code is taken from zerorpc/core.py:
        timeout = kargs.get('timeout', self._timeout)
        channel = self._multiplexer.channel()
        bufchan = BufferedChannel(channel, inqueue_size=kargs.get('slots', 100))

        xheader = self._context.hook_get_task_context()
        if hasattr(bufchan, 'new_event'):
            request_event = bufchan.new_event(method, args, xheader)
        else:
            request_event = bufchan.create_event(method, args, xheader)
        self._context.hook_client_before_request(request_event)
        bufchan.emit_event(request_event)

        try:
            if kargs.get('async', False) is False:
                return self._process_response(request_event, bufchan, timeout)

            async_result = gevent.event.AsyncResult()
            gevent.spawn(self._process_response, request_event, bufchan, timeout).link(async_result)
            return async_result
        except:
            # XXX: This is going to be closed twice if async is false and
            # _process_response raises an exception. I wonder if the above
            # async branch can raise an exception too, if no we can just remove
            # this code.
            bufchan.close()
            raise
Example #2
0
    def __call__(self, method, *args, **kargs):
        # We modify zerorpc's __call__ method to remove the heartbeat feature since it may cause server-side requests
        # to get interrupted during processing if it detects a lost remote and it may also fail if the client and
        # server don't have the same heartbeat frequency set.
        #
        # The following code is taken from zerorpc/core.py:
        timeout = kargs.get('timeout', self._timeout)
        channel = self._multiplexer.channel()
        bufchan = BufferedChannel(channel,
                                  inqueue_size=kargs.get('slots', 100))

        xheader = self._context.hook_get_task_context()
        if hasattr(bufchan, 'new_event'):
            request_event = bufchan.new_event(method, args, xheader)
        else:
            request_event = bufchan.create_event(method, args, xheader)
        self._context.hook_client_before_request(request_event)
        bufchan.emit_event(request_event)

        try:
            if kargs.get('async', False) is False:
                return self._process_response(request_event, bufchan, timeout)

            async_result = gevent.event.AsyncResult()
            gevent.spawn(self._process_response, request_event, bufchan,
                         timeout).link(async_result)
            return async_result
        except:
            # XXX: This is going to be closed twice if async is false and
            # _process_response raises an exception. I wonder if the above
            # async branch can raise an exception too, if no we can just remove
            # this code.
            bufchan.close()
            raise
Example #3
0
    def __call__(self, method, *args, **kargs):
        timeout = kargs.get('timeout', self._timeout)
        channel = self._multiplexer.channel()
        hbchan = HeartBeatOnChannel(channel, freq=self._heartbeat_freq,
                                    passive=self._passive_heartbeat)
        bufchan = BufferedChannel(hbchan, inqueue_size=kargs.get('slots', 100))

        request_event = self._generate_request_event(bufchan, method, args)
        bufchan.emit_event(request_event)

        try:
            if kargs.get('async', False) is False:
                return self._process_response(request_event, bufchan, timeout)

            async_result = gevent.event.AsyncResult()
            gevent.spawn(self._process_response, request_event, bufchan,
                         timeout).link(async_result)
            return async_result
        except:
            # XXX: This is going to be closed twice if async is false and
            # _process_response raises an exception. I wonder if the above
            # async branch can raise an exception too, if no we can just remove
            # this code.
            bufchan.close()
            raise
Example #4
0
    def __call__(self, method, *args, **kargs):
        timeout = kargs.get('timeout', self._timeout)
        channel = self._multiplexer.channel()
        hbchan = HeartBeatOnChannel(channel, freq=self._heartbeat_freq,
                                    passive=self._passive_heartbeat)
        bufchan = BufferedChannel(hbchan, inqueue_size=kargs.get('slots', 100))

        request_event = self._generate_request_event(bufchan, method, args)
        bufchan.emit_event(request_event)

        try:
            if kargs.get('async', False) is False:
                return self._process_response(request_event, bufchan, timeout)

            async_result = gevent.event.AsyncResult()
            gevent.spawn(self._process_response, request_event, bufchan,
                         timeout).link(async_result)
            return async_result
        except:
            # XXX: This is going to be closed twice if async is false and
            # _process_response raises an exception. I wonder if the above
            # async branch can raise an exception too, if no we can just remove
            # this code.
            bufchan.close()
            raise