Ejemplo n.º 1
0
    def retry(self, connector=None):
        """Have this connector connect again, after a suitable delay.
        """
        if not self.continueTrying:
            if self.noisy:
                log.msg("Abandoning %s on explicit request" % (connector,))
            return

        if connector is None:
            if self.connector is None:
                raise ValueError("no connector to retry")
            else:
                connector = self.connector

        self.retries += 1
        if self.maxRetries is not None and (self.retries > self.maxRetries):
            if self.noisy:
                log.msg("Abandoning %s after %d retries." %
                        (connector, self.retries))
            return

        self.delay = min(self.delay * self.factor, self.maxDelay)
        if self.jitter:
            self.delay = random.normalvariate(self.delay,
                                              self.delay * self.jitter)

        if self.noisy:
            log.msg("%s will retry in %d seconds" % (connector, self.delay,))
        from include.twisted.internet import reactor

        def reconnector():
            self._callID = None
            connector.connect()
        self._callID = reactor.callLater(self.delay, reconnector)
Ejemplo n.º 2
0
    def setTimeout(self, seconds, timeoutFunc=timeout, *args, **kw):
        """Set a timeout function to be triggered if I am not called.

        @param seconds: How long to wait (from now) before firing the
        timeoutFunc.

        @param timeoutFunc: will receive the Deferred and *args, **kw as its
        arguments.  The default timeoutFunc will call the errback with a
        L{TimeoutError}.
        """
        warnings.warn(
            "Deferred.setTimeout is deprecated.  Look for timeout "
            "support specific to the API you are using instead.",
            DeprecationWarning, stacklevel=2)

        if self.called:
            return
        assert not self.timeoutCall, "Don't call setTimeout twice on the same Deferred."

        from include.twisted.internet import reactor
        self.timeoutCall = reactor.callLater(
            seconds,
            lambda: self.called or timeoutFunc(self, *args, **kw))
        return self.timeoutCall
Ejemplo n.º 3
0
 def sendKeepAlive(self):
     self.sendFLAP("",0x05)
     self.stopKeepAliveID = reactor.callLater(self.keepAliveDelay, self.sendKeepAlive)
Ejemplo n.º 4
0
 def setKeepAlive(self,t):
     self.keepAliveDelay=t
     self.stopKeepAlive()
     self.stopKeepAliveID = reactor.callLater(t, self.sendKeepAlive)
Ejemplo n.º 5
0
 def _loseConnection(self):
     self.stopReading()
     if self.connected: # actually means if we are *listening*
         from include.twisted.internet import reactor
         reactor.callLater(0, self.connectionLost)