當前位置: 首頁>>代碼示例>>Python>>正文


Python error.AlreadyCancelled方法代碼示例

本文整理匯總了Python中twisted.internet.error.AlreadyCancelled方法的典型用法代碼示例。如果您正苦於以下問題:Python error.AlreadyCancelled方法的具體用法?Python error.AlreadyCancelled怎麽用?Python error.AlreadyCancelled使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twisted.internet.error的用法示例。


在下文中一共展示了error.AlreadyCancelled方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: cancel

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import AlreadyCancelled [as 別名]
def cancel(self):
        """Unschedule this call

        @raise AlreadyCancelled: Raised if this call has already been
        unscheduled.

        @raise AlreadyCalled: Raised if this call has already been made.
        """
        if self.cancelled:
            raise error.AlreadyCancelled
        elif self.called:
            raise error.AlreadyCalled
        else:
            self.canceller(self)
            self.cancelled = 1
            if self.debug:
                self._str = bytes(self)
            del self.func, self.args, self.kw 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:20,代碼來源:base.py

示例2: reset

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import AlreadyCancelled [as 別名]
def reset(self, secondsFromNow):
        """Reschedule this call for a different time

        @type secondsFromNow: C{float}
        @param secondsFromNow: The number of seconds from the time of the
        C{reset} call at which this call will be scheduled.

        @raise AlreadyCancelled: Raised if this call has been cancelled.
        @raise AlreadyCalled: Raised if this call has already been made.
        """
        if self.cancelled:
            raise error.AlreadyCancelled
        elif self.called:
            raise error.AlreadyCalled
        else:
            newTime = self.seconds() + secondsFromNow
            if newTime < self.time:
                self.delayed_time = 0
                self.time = newTime
                self.resetter(self)
            else:
                self.delayed_time = newTime - self.time 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:24,代碼來源:base.py

示例3: delay

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import AlreadyCancelled [as 別名]
def delay(self, secondsLater):
        """Reschedule this call for a later time

        @type secondsLater: C{float}
        @param secondsLater: The number of seconds after the originally
        scheduled time for which to reschedule this call.

        @raise AlreadyCancelled: Raised if this call has been cancelled.
        @raise AlreadyCalled: Raised if this call has already been made.
        """
        if self.cancelled:
            raise error.AlreadyCancelled
        elif self.called:
            raise error.AlreadyCalled
        else:
            self.delayed_time += secondsLater
            if self.delayed_time < 0:
                self.activate_delay()
                self.resetter(self) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:21,代碼來源:base.py

示例4: enqueuedJob

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import AlreadyCancelled [as 別名]
def enqueuedJob(self):
        """
        Reschedule the work check loop to run right now. This should be called in response to "external" activity that
        might want to "speed up" the job queue polling because new work may have been added.
        """

        # Only need to do this if the actual poll interval is greater than the default rapid value
        if self._actualPollInterval == self.queuePollInterval:
            return

        # Bump time of last work so that we go back to the rapid (default) polling interval
        self._timeOfLastWork = time.time()

        # Reschedule the outstanding delayed call (handle exceptions by ignoring if its already running or
        # just finished)
        try:
            if self._workCheckCall is not None:
                self._workCheckCall.reset(0)
        except (AlreadyCalled, AlreadyCancelled):
            pass 
開發者ID:apple,項目名稱:ccs-twistedextensions,代碼行數:22,代碼來源:queue.py

示例5: cancel

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import AlreadyCancelled [as 別名]
def cancel(self):
        """Unschedule this call

        @raise AlreadyCancelled: Raised if this call has already been
        unscheduled.

        @raise AlreadyCalled: Raised if this call has already been made.
        """
        if self.cancelled:
            raise error.AlreadyCancelled
        elif self.called:
            raise error.AlreadyCalled
        else:
            self.canceller(self)
            self.cancelled = 1
            if self.debug:
                self._repr = repr(self)
            del self.func, self.args, self.kw 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:20,代碼來源:base.py

示例6: cancel

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import AlreadyCancelled [as 別名]
def cancel(self):
        """Unschedule this call

        @raise AlreadyCancelled: Raised if this call has already been
        unscheduled.

        @raise AlreadyCalled: Raised if this call has already been made.
        """
        if self.cancelled:
            raise error.AlreadyCancelled
        elif self.called:
            raise error.AlreadyCalled
        else:
            self.canceller(self)
            self.cancelled = 1
            if self.debug:
                self._str = str(self)
            del self.func, self.args, self.kw 
開發者ID:CanonicalLtd,項目名稱:landscape-client,代碼行數:20,代碼來源:clock.py

示例7: reset

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import AlreadyCancelled [as 別名]
def reset(self, secondsFromNow):
        """Reschedule this call for a different time

        @type secondsFromNow: C{float}
        @param secondsFromNow: The number of seconds from the time of the
        C{reset} call at which this call will be scheduled.

        @raise AlreadyCancelled: Raised if this call has been cancelled.
        @raise AlreadyCalled: Raised if this call has already been made.
        """
        if self.cancelled:
            raise error.AlreadyCancelled
        elif self.called:
            raise error.AlreadyCalled
        else:
            if self.seconds is None:
                new_time = seconds() + secondsFromNow
            else:
                new_time = self.seconds() + secondsFromNow
            if new_time < self.time:
                self.delayed_time = 0
                self.time = new_time
                self.resetter(self)
            else:
                self.delayed_time = new_time - self.time 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:27,代碼來源:base.py

示例8: testCallLater

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import AlreadyCancelled [as 別名]
def testCallLater(self):
        # add and remove a callback
        def bad():
            raise RuntimeError, "this shouldn't have been called"
        i = reactor.callLater(0.1, bad)
        i.cancel()

        self.assertRaises(error.AlreadyCancelled, i.cancel)

        d = defer.Deferred()
        i = reactor.callLater(0.5, self._callback, d, 1, a=1)
        start = time.time()

        def check(ignored):
            self.assertApproximates(self._calledTime, start + 0.5, 0.2 )
            self.assertRaises(error.AlreadyCalled, i.cancel)
            del self._called
            del self._calledTime
        d.addCallback(check)
        return d 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:22,代碼來源:test_internet.py

示例9: test_cancelCancelledDelayedCall

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import AlreadyCancelled [as 別名]
def test_cancelCancelledDelayedCall(self):
        """
        Test that cancelling a DelayedCall which has already been cancelled
        raises the appropriate exception.
        """
        call = reactor.callLater(0, lambda: None)
        call.cancel()
        self.assertRaises(error.AlreadyCancelled, call.cancel) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:10,代碼來源:test_internet.py

示例10: cancel

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import AlreadyCancelled [as 別名]
def cancel(self):

        """Cancels the timer if it was running, does nothing otherwise"""

        try:
            self.delayed_call.cancel()
            self.status = False
        except (AttributeError, error.AlreadyCalled, error.AlreadyCancelled):
            pass 
開發者ID:smartbgp,項目名稱:yabgp,代碼行數:11,代碼來源:timer.py

示例11: reset

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import AlreadyCancelled [as 別名]
def reset(self, seconds_fromnow):
        """Resets an already running timer, or starts it if it wasn't running.

        :param seconds_fromnow : restart timer
        """

        try:
            self.status = True
            self.delayed_call.reset(seconds_fromnow)
        except (AttributeError, error.AlreadyCalled, error.AlreadyCancelled):
            self.delayed_call = reactor.callLater(seconds_fromnow, self.callable) 
開發者ID:smartbgp,項目名稱:yabgp,代碼行數:13,代碼來源:timer.py

示例12: cancelTimeout

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import AlreadyCancelled [as 別名]
def cancelTimeout(self):
        """
        Cancel the timeout.

        If the timeout was already cancelled, this does nothing.
        """
        self.timeoutPeriod = None
        if self.timeoutCall:
            try:
                self.timeoutCall.cancel()
            except (error.AlreadyCalled, error.AlreadyCancelled):
                pass
            self.timeoutCall = None 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:15,代碼來源:policies.py

示例13: abort_request

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import AlreadyCancelled [as 別名]
def abort_request(self, request):
        """Called to abort request on timeout"""
        self.timedout = True
        if not request.called:
            try:
                request.cancel()
            except error.AlreadyCancelled:
                return 
開發者ID:calston,項目名稱:tensor,代碼行數:10,代碼來源:utils.py

示例14: remove_alarm

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import AlreadyCancelled [as 別名]
def remove_alarm(self, handle):
        """
        Remove an alarm.

        Returns True if the alarm exists, False otherwise
        """
        from twisted.internet.error import AlreadyCancelled, AlreadyCalled
        try:
            handle.cancel()
            return True
        except AlreadyCancelled:
            return False
        except AlreadyCalled:
            return False 
開發者ID:AnyMesh,項目名稱:anyMesh-Python,代碼行數:16,代碼來源:main_loop.py

示例15: getSession

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import AlreadyCancelled [as 別名]
def getSession(self, sessionInterface=None, forceNotSecure=False):
        """
        Check if there is a session cookie, and if not, create it.

        By default, the cookie with be secure for HTTPS requests and not secure
        for HTTP requests.  If for some reason you need access to the insecure
        cookie from a secure request you can set C{forceNotSecure = True}.

        @param forceNotSecure: Should we retrieve a session that will be
            transmitted over HTTP, even if this L{Request} was delivered over
            HTTPS?
        @type forceNotSecure: L{bool}
        """
        # Make sure we aren't creating a secure session on a non-secure page
        secure = self.isSecure() and not forceNotSecure

        if not secure:
            cookieString = b"TWISTED_SESSION"
            sessionAttribute = "_insecureSession"
        else:
            cookieString = b"TWISTED_SECURE_SESSION"
            sessionAttribute = "_secureSession"

        session = getattr(self, sessionAttribute)

        if session is not None:
            # We have a previously created session.
            try:
                # Refresh the session, to keep it alive.
                session.touch()
            except (AlreadyCalled, AlreadyCancelled):
                # Session has already expired.
                session = None

        if session is None:
            # No session was created yet for this request.
            cookiename = b"_".join([cookieString] + self.sitepath)
            sessionCookie = self.getCookie(cookiename)
            if sessionCookie:
                try:
                    session = self.site.getSession(sessionCookie)
                except KeyError:
                    pass
            # if it still hasn't been set, fix it up.
            if not session:
                session = self.site.makeSession()
                self.addCookie(cookiename, session.uid, path=b"/",
                               secure=secure)

        setattr(self, sessionAttribute, session)

        if sessionInterface:
            return session.getComponent(sessionInterface)

        return session 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:57,代碼來源:server.py


注:本文中的twisted.internet.error.AlreadyCancelled方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。