我们从Python开源项目中,提取了以下26个代码示例,用于说明如何使用twisted.internet.error.AlreadyCalled()。
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 test_cancelCalledDelayedCallSynchronous(self): """ Test that cancelling a DelayedCall in the DelayedCall's function as that function is being invoked by the DelayedCall raises the appropriate exception. """ d = Deferred() def later(): try: self.assertRaises(error.AlreadyCalled, call.cancel) except: d.errback() else: d.callback(None) call = reactor.callLater(0, later) return d
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 testAdvanceCancel(self): """ Test attemping to cancel the call in a callback. AlreadyCalled should be raised, not for example a ValueError from removing the call from Clock.calls. This requires call.called to be set before the callback is called. """ c = task.Clock() def cb(): self.assertRaises(error.AlreadyCalled, call.cancel) call = c.callLater(1, cb) c.advance(1)
def removeTimer(self, timer): try: timer.cancel() except error.AlreadyCalled: pass self.timers.remove(timer)
def cancelTimeout(self): """Cancel the timeout. If the timeout was already cancelled, this does nothing. """ if self.timeoutCall: try: self.timeoutCall.cancel() except error.AlreadyCalled: pass self.timeoutCall = None
def _cancel_timer(self): try: self.timer.cancel() except AlreadyCalled: pass
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 testAdvanceCancel(self): """ Test attempting to cancel the call in a callback. AlreadyCalled should be raised, not for example a ValueError from removing the call from Clock.calls. This requires call.called to be set before the callback is called. """ c = task.Clock() def cb(): self.assertRaises(error.AlreadyCalled, call.cancel) call = c.callLater(1, cb) c.advance(1)
def cancelTimeout(self): """ Cancel the timeout. If the timeout was already cancelled, this does nothing. """ if self.timeoutCall: try: self.timeoutCall.cancel() except error.AlreadyCalled: pass self.timeoutCall = None