Пример #1
0
 def callAsyncNoPoll(self, method, *args):
     # Like CallAsync but doesn't poll.  This exists so that we can
     # send invalidations atomically to all clients without
     # allowing any client to sneak in a load request.
     if self.closed:
         raise DisconnectedError()
     self.send_call(method, args, ASYNC)
Пример #2
0
    def wait(self, msgid):
        """Invoke asyncore mainloop and wait for reply."""
        if __debug__:
            self.log("wait(%d), async=%d" % (msgid, self.is_async()),
                     level=TRACE)
        if self.is_async():
            self._pull_trigger()

        # Delay used when we call asyncore.poll() directly.
        # Start with a 1 msec delay, double until 1 sec.
        delay = 0.001

        self.replies_cond.acquire()
        try:
            while 1:
                if self.closed:
                    raise DisconnectedError()
                reply = self.replies.get(msgid)
                if reply is not None:
                    del self.replies[msgid]
                    if __debug__:
                        self.log("wait(%d): reply=%s" %
                                 (msgid, short_repr(reply)),
                                 level=TRACE)
                    return reply
                assert self.is_async()  # XXX we're such cowards
                self.replies_cond.wait()
        finally:
            self.replies_cond.release()
Пример #3
0
    def message_output(self, message):
        if __debug__:
            if self._debug:
                log("message_output %d bytes: %s hmac=%d" %
                    (len(message), short_repr(message), self.__hmac_send and 1
                     or 0),
                    level=TRACE)

        if self.__closed:
            raise DisconnectedError(
                "This action is temporarily unavailable.<p>")
        self.__output_lock.acquire()
        try:
            # do two separate appends to avoid copying the message string
            if self.__hmac_send:
                self.__output.append(struct.pack(">I", len(message) | MAC_BIT))
                self.__hmac_send.update(message)
                self.__output.append(self.__hmac_send.digest())
            else:
                self.__output.append(struct.pack(">I", len(message)))
            if len(message) <= SEND_SIZE:
                self.__output.append(message)
            else:
                for i in range(0, len(message), SEND_SIZE):
                    self.__output.append(message[i:i + SEND_SIZE])
        finally:
            self.__output_lock.release()
Пример #4
0
 def _deferred_call(self, method, *args):
     if self.closed:
         raise DisconnectedError()
     msgid = self.send_call(method, args, 0)
     if self.is_async():
         self.trigger.pull_trigger()
     else:
         asyncore.poll(0.01, self._singleton)
     return msgid
Пример #5
0
 def call(self, method, *args):
     if self.closed:
         raise DisconnectedError()
     msgid = self.send_call(method, args, 0)
     r_flags, r_args = self.wait(msgid)
     if (isinstance(r_args, tuple) and len(r_args) > 1
             and type(r_args[0]) == exception_type_type
             and issubclass(r_args[0], Exception)):
         inst = r_args[1]
         raise inst  # error raised by server
     else:
         return r_args
Пример #6
0
    def wait(self, msgid):
        """Invoke asyncore mainloop and wait for reply."""
        if __debug__:
            self.log("wait(%d), async=%d" % (msgid, self.is_async()),
                     level=TRACE)
        if self.is_async():
            self._pull_trigger()

        # Delay used when we call asyncore.poll() directly.
        # Start with a 1 msec delay, double until 1 sec.
        delay = 0.001

        self.replies_cond.acquire()
        try:
            while 1:
                if self.closed:
                    raise DisconnectedError()
                reply = self.replies.get(msgid)
                if reply is not None:
                    del self.replies[msgid]
                    if __debug__:
                        self.log("wait(%d): reply=%s" %
                                 (msgid, short_repr(reply)),
                                 level=TRACE)
                    return reply
                if self.is_async():
                    self.replies_cond.wait(10.0)
                else:
                    self.replies_cond.release()
                    try:
                        try:
                            if __debug__:
                                self.log("wait(%d): asyncore.poll(%s)" %
                                         (msgid, delay),
                                         level=TRACE)
                            asyncore.poll(delay, self._singleton)
                            if delay < 1.0:
                                delay += delay
                        except select.error, err:
                            self.log("Closing.  asyncore.poll() raised %s." %
                                     err,
                                     level=BLATHER)
                            self.close()
                    finally:
                        self.replies_cond.acquire()
        finally:
            self.replies_cond.release()
Пример #7
0
    def wait(self, msgid):
        """Invoke asyncore mainloop and wait for reply."""
        if debug_zrpc:
            self.log("wait(%d)" % msgid, level=TRACE)

        self.trigger.pull_trigger()

        self.replies_cond.acquire()
        try:
            while 1:
                if self.closed:
                    raise DisconnectedError()
                reply = self.replies.get(msgid, self)
                if reply is not self:
                    del self.replies[msgid]
                    if debug_zrpc:
                        self.log("wait(%d): reply=%s" %
                                 (msgid, short_repr(reply)), level=TRACE)
                    return reply
                self.replies_cond.wait()
        finally:
            self.replies_cond.release()
Пример #8
0
 def callAsync(self, method, *args):
     if self.closed:
         raise DisconnectedError()
     self.send_call(method, args, ASYNC)
     self.poll()
Пример #9
0
 def _deferred_call(self, method, *args):
     if self.closed:
         raise DisconnectedError()
     msgid = self.send_call(method, args, 0)
     asyncore.poll(0.01, self._singleton)
     return msgid
Пример #10
0
 def message_output(self, message):
     if self.__closed:
         raise DisconnectedError(
             "This action is temporarily unavailable.<p>")
     self.__output_messages.append(message)
Пример #11
0
 def _deferred_call(self, method, *args):
     if self.closed:
         raise DisconnectedError()
     msgid = self.send_call(method, args)
     self.trigger.pull_trigger()
     return msgid