我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用twisted.internet.error.AlreadyCancelled()。
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
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
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)
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
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
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
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)
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
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