本文整理匯總了Python中twisted.internet.base.DelayedCall方法的典型用法代碼示例。如果您正苦於以下問題:Python base.DelayedCall方法的具體用法?Python base.DelayedCall怎麽用?Python base.DelayedCall使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.internet.base
的用法示例。
在下文中一共展示了base.DelayedCall方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: callLater
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import DelayedCall [as 別名]
def callLater(self, seconds, f, *args, **kwargs):
def run():
dc.called = True
self._delayedCalls.remove(dc)
f(*args, **kwargs)
handle = self._asyncioEventloop.call_later(seconds, run)
dchandle = _DCHandle(handle)
def cancel(dc):
self._delayedCalls.remove(dc)
dchandle.cancel()
def reset(dc):
dchandle.handle = self._asyncioEventloop.call_at(dc.time, run)
dc = DelayedCall(self.seconds() + seconds, run, (), {},
cancel, reset, seconds=self.seconds)
self._delayedCalls.add(dc)
return dc
示例2: test_cleanPendingReturnsDelayedCallStrings
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import DelayedCall [as 別名]
def test_cleanPendingReturnsDelayedCallStrings(self):
"""
The Janitor produces string representations of delayed calls from the
delayed call cleanup method. It gets the string representations
*before* cancelling the calls; this is important because cancelling the
call removes critical debugging information from the string
representation.
"""
delayedCall = DelayedCall(300, lambda: None, (), {},
lambda x: None, lambda x: None,
seconds=lambda: 0)
delayedCallString = str(delayedCall)
reactor = StubReactor([delayedCall])
jan = _Janitor(None, None, reactor=reactor)
strings = jan._cleanPending()
self.assertEqual(strings, [delayedCallString])
示例3: test_postCaseCleanupWithErrors
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import DelayedCall [as 別名]
def test_postCaseCleanupWithErrors(self):
"""
The post-case cleanup method will return False and call C{addError} on
the result with a L{DirtyReactorAggregateError} Failure if there are
pending calls.
"""
delayedCall = DelayedCall(300, lambda: None, (), {},
lambda x: None, lambda x: None,
seconds=lambda: 0)
delayedCallString = str(delayedCall)
reactor = StubReactor([delayedCall], [])
test = object()
reporter = StubErrorReporter()
jan = _Janitor(test, reporter, reactor=reactor)
self.assertFalse(jan.postCaseCleanup())
self.assertEqual(len(reporter.errors), 1)
self.assertEqual(reporter.errors[0][1].value.delayedCalls,
[delayedCallString])
示例4: test_postClassCleanupWithPendingCallErrors
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import DelayedCall [as 別名]
def test_postClassCleanupWithPendingCallErrors(self):
"""
The post-class cleanup method call C{addError} on the result with a
L{DirtyReactorAggregateError} Failure if there are pending calls.
"""
delayedCall = DelayedCall(300, lambda: None, (), {},
lambda x: None, lambda x: None,
seconds=lambda: 0)
delayedCallString = str(delayedCall)
reactor = StubReactor([delayedCall], [])
test = object()
reporter = StubErrorReporter()
jan = _Janitor(test, reporter, reactor=reactor)
jan.postClassCleanup()
self.assertEqual(len(reporter.errors), 1)
self.assertEqual(reporter.errors[0][1].value.delayedCalls,
[delayedCallString])
示例5: test_cancelDelayedCall
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import DelayedCall [as 別名]
def test_cancelDelayedCall(self):
"""
Test that when a DelayedCall is cancelled it does not run.
"""
called = []
def function():
called.append(None)
call = reactor.callLater(0, function)
call.cancel()
# Schedule a call in two "iterations" to check to make sure that the
# above call never ran.
d = Deferred()
def check():
try:
self.assertEqual(called, [])
except:
d.errback()
else:
d.callback(None)
reactor.callLater(0, reactor.callLater, 0, check)
return d
示例6: test_cancelCalledDelayedCallAsynchronous
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import DelayedCall [as 別名]
def test_cancelCalledDelayedCallAsynchronous(self):
"""
Test that cancelling a DelayedCall after it has run its function
raises the appropriate exception.
"""
d = Deferred()
def check():
try:
self.assertRaises(error.AlreadyCalled, call.cancel)
except:
d.errback()
else:
d.callback(None)
def later():
reactor.callLater(0, check)
call = reactor.callLater(0, later)
return d
示例7: test_cancelCalledDelayedCallSynchronous
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import DelayedCall [as 別名]
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
示例8: test_str
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import DelayedCall [as 別名]
def test_str(self):
"""
The string representation of a L{DelayedCall} instance, as returned by
C{str}, includes the unsigned id of the instance, as well as its state,
the function to be called, and the function arguments.
"""
def nothing():
pass
dc = DelayedCall(12, nothing, (3, ), {"A": 5}, None, None, lambda: 1.5)
ids = {dc: 200}
def fakeID(obj):
try:
return ids[obj]
except (TypeError, KeyError):
return id(obj)
self.addCleanup(setIDFunction, setIDFunction(fakeID))
self.assertEquals(
str(dc),
"<DelayedCall 0xc8 [10.5s] called=0 cancelled=0 nothing(3, A=5)>")
示例9: test_cleanPendingReturnsDelayedCallStrings
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import DelayedCall [as 別名]
def test_cleanPendingReturnsDelayedCallStrings(self):
"""
The Janitor produces string representations of delayed calls from the
delayed call cleanup method. It gets the string representations
*before* cancelling the calls; this is important because cancelling the
call removes critical debugging information from the string
representation.
"""
delayedCall = DelayedCall(300, lambda: None, (), {},
lambda x: None, lambda x: None,
seconds=lambda: 0)
delayedCallString = str(delayedCall)
reactor = StubReactor([delayedCall])
jan = _Janitor(None, None, reactor=reactor)
strings = jan._cleanPending()
self.assertEquals(strings, [delayedCallString])
示例10: test_postCaseCleanupWithErrors
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import DelayedCall [as 別名]
def test_postCaseCleanupWithErrors(self):
"""
The post-case cleanup method will return False and call C{addError} on
the result with a L{DirtyReactorAggregateError} Failure if there are
pending calls.
"""
delayedCall = DelayedCall(300, lambda: None, (), {},
lambda x: None, lambda x: None,
seconds=lambda: 0)
delayedCallString = str(delayedCall)
reactor = StubReactor([delayedCall], [])
test = object()
reporter = StubErrorReporter()
jan = _Janitor(test, reporter, reactor=reactor)
self.assertFalse(jan.postCaseCleanup())
self.assertEquals(len(reporter.errors), 1)
self.assertEquals(reporter.errors[0][1].value.delayedCalls,
[delayedCallString])
示例11: test_postClassCleanupWithPendingCallErrors
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import DelayedCall [as 別名]
def test_postClassCleanupWithPendingCallErrors(self):
"""
The post-class cleanup method call C{addError} on the result with a
L{DirtyReactorAggregateError} Failure if there are pending calls.
"""
delayedCall = DelayedCall(300, lambda: None, (), {},
lambda x: None, lambda x: None,
seconds=lambda: 0)
delayedCallString = str(delayedCall)
reactor = StubReactor([delayedCall], [])
test = object()
reporter = StubErrorReporter()
jan = _Janitor(test, reporter, reactor=reactor)
jan.postClassCleanup()
self.assertEquals(len(reporter.errors), 1)
self.assertEquals(reporter.errors[0][1].value.delayedCalls,
[delayedCallString])
示例12: stop
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import DelayedCall [as 別名]
def stop(self):
"""Suspend leadership duties immediately"""
log.debug('stopping')
self.halted = True
# any active cancellations, releases, etc., should happen here
if isinstance(self.reassignment_soak_timer, DelayedCall):
if not self.reassignment_soak_timer.called:
self.reassignment_soak_timer.cancel()
if isinstance(self.core_store_reassignment_soak_timer, DelayedCall):
if not self.core_store_reassignment_soak_timer.called:
self.core_store_reassignment_soak_timer.cancel()
log.info('stopped')
# Private methods:
示例13: callLater
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import DelayedCall [as 別名]
def callLater(self, when, what, *a, **kw):
"""
See L{twisted.internet.interfaces.IReactorTime.callLater}.
"""
dc = base.DelayedCall(self.seconds() + when,
what, a, kw,
self.calls.remove,
lambda c: None,
self.seconds)
self.calls.append(dc)
self._sortCalls()
return dc
示例14: _getDelayedCallAt
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import DelayedCall [as 別名]
def _getDelayedCallAt(self, time):
"""
Get a L{DelayedCall} instance at a given C{time}.
@param time: The absolute time at which the returned L{DelayedCall}
will be scheduled.
"""
def noop(call):
pass
return DelayedCall(time, lambda: None, (), {}, noop, noop, None)
示例15: setUp
# 需要導入模塊: from twisted.internet import base [as 別名]
# 或者: from twisted.internet.base import DelayedCall [as 別名]
def setUp(self):
"""
Create two L{DelayedCall} instanced scheduled to run at different
times.
"""
self.zero = self._getDelayedCallAt(0)
self.one = self._getDelayedCallAt(1)