本文整理汇总了Python中twisted.internet.reactor.crash方法的典型用法代码示例。如果您正苦于以下问题:Python reactor.crash方法的具体用法?Python reactor.crash怎么用?Python reactor.crash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.reactor
的用法示例。
在下文中一共展示了reactor.crash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testCrash
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import crash [as 别名]
def testCrash(self):
"""reactor.crash should NOT fire shutdown triggers"""
self.counter = 0
self.problem = 0
self.addTrigger("before", "shutdown", self.count)
# reactor.crash called from an "after-startup" trigger is too early
# for the gtkreactor: gtk_mainloop is not yet running. Same is true
# when called with reactor.callLater(0). Must be >0 seconds in the
# future to let gtk_mainloop start first.
self.addTimer(0.1, self.crash)
t = self.addTimer(5, self.timeout)
reactor.run()
# this will fire reactor.crash, which ought to exit .run without
# running the event triggers
self.failUnless(self.counter == 0,
"reactor.crash invoked shutdown triggers, "
"but it isn't supposed to")
self.failIf(self.problem, "the test timed out")
self.removeTimer(t)
示例2: __init__
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import crash [as 别名]
def __init__(self, master, create, callback, items):
Tkinter.Menu.__init__(self, master)
cmdMenu = Tkinter.Menu(self)
self.add_cascade(label="Actions", menu=cmdMenu)
cmdMenu.add_command(label='Create', command=create)
cmdMenu.add_separator()
cmdMenu.add_command(label='Quit', command=reactor.crash)
tapMenu = Tkinter.Menu(self)
self.add_cascade(label="Applications", menu=tapMenu)
for item in items:
tapMenu.add_command(
label=item, command=lambda i=item, c = callback: c(i)
)
示例3: _run
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import crash [as 别名]
def _run(self, methodName, result):
from twisted.internet import reactor
timeout = self.getTimeout()
def onTimeout(d):
e = defer.TimeoutError("%r (%s) still running at %s secs"
% (self, methodName, timeout))
f = failure.Failure(e)
# try to errback the deferred that the test returns (for no gorram
# reason) (see issue1005 and test_errorPropagation in
# test_deferred)
try:
d.errback(f)
except defer.AlreadyCalledError:
# if the deferred has been called already but the *back chain
# is still unfinished, crash the reactor and report timeout
# error ourself.
reactor.crash()
self._timedOut = True # see self._wait
todo = self.getTodo()
if todo is not None and todo.expected(f):
result.addExpectedFailure(self, f, todo)
else:
result.addError(self, f)
onTimeout = utils.suppressWarnings(
onTimeout, util.suppress(category=DeprecationWarning))
method = getattr(self, methodName)
if inspect.isgeneratorfunction(method):
exc = TypeError(
'%r is a generator function and therefore will never run' % (
method,))
return defer.fail(exc)
d = defer.maybeDeferred(
utils.runWithWarningsSuppressed, self._getSuppress(), method)
call = reactor.callLater(timeout, onTimeout, d)
d.addBoth(lambda x : call.active() and call.cancel() or x)
return d
示例4: _makeReactorMethod
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import crash [as 别名]
def _makeReactorMethod(self, name):
"""
Create a method which wraps the reactor method C{name}. The new
method issues a deprecation warning and calls the original.
"""
def _(*a, **kw):
warnings.warn("reactor.%s cannot be used inside unit tests. "
"In the future, using %s will fail the test and may "
"crash or hang the test run."
% (name, name),
stacklevel=2, category=DeprecationWarning)
return self._reactorMethods[name](*a, **kw)
return _
示例5: _deprecateReactor
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import crash [as 别名]
def _deprecateReactor(self, reactor):
"""
Deprecate C{iterate}, C{crash} and C{stop} on C{reactor}. That is,
each method is wrapped in a function that issues a deprecation
warning, then calls the original.
@param reactor: The Twisted reactor.
"""
self._reactorMethods = {}
for name in ['crash', 'iterate', 'stop']:
self._reactorMethods[name] = getattr(reactor, name)
setattr(reactor, name, self._makeReactorMethod(name))
示例6: test_callbackReturnsNonCallingDeferred
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import crash [as 别名]
def test_callbackReturnsNonCallingDeferred(self):
#hacky timeout
# raises KeyboardInterrupt because Trial sucks
from twisted.internet import reactor
call = reactor.callLater(2, reactor.crash)
result = self.runTest('test_calledButNeverCallback')
if call.active():
call.cancel()
self.assertFalse(result.wasSuccessful())
self._wasTimeout(result.errors[0][1])
# The test loader erroneously attempts to run this:
示例7: test_callbackReturnsNonCallingDeferred
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import crash [as 别名]
def test_callbackReturnsNonCallingDeferred(self):
#hacky timeout
# raises KeyboardInterrupt because Trial sucks
from twisted.internet import reactor
call = reactor.callLater(2, reactor.crash)
result = self.runTest('test_calledButNeverCallback')
if call.active():
call.cancel()
self.failIf(result.wasSuccessful())
self._wasTimeout(result.errors[0][1])
示例8: _run
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import crash [as 别名]
def _run(self, methodName, result):
from twisted.internet import reactor
timeout = self.getTimeout()
def onTimeout(d):
e = defer.TimeoutError("%r (%s) still running at %s secs"
% (self, methodName, timeout))
f = failure.Failure(e)
# try to errback the deferred that the test returns (for no gorram
# reason) (see issue1005 and test_errorPropagation in
# test_deferred)
try:
d.errback(f)
except defer.AlreadyCalledError:
# if the deferred has been called already but the *back chain
# is still unfinished, crash the reactor and report timeout
# error ourself.
reactor.crash()
self._timedOut = True # see self._wait
todo = self.getTodo()
if todo is not None and todo.expected(f):
result.addExpectedFailure(self, f, todo)
else:
result.addError(self, f)
onTimeout = utils.suppressWarnings(
onTimeout, util.suppress(category=DeprecationWarning))
method = getattr(self, methodName)
d = defer.maybeDeferred(utils.runWithWarningsSuppressed,
self.getSuppress(), method)
call = reactor.callLater(timeout, onTimeout, d)
d.addBoth(lambda x : call.active() and call.cancel() or x)
return d
示例9: test_callbackReturnsNonCallingDeferred
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import crash [as 别名]
def test_callbackReturnsNonCallingDeferred(self):
#hacky timeout
# raises KeyboardInterrupt because Trial sucks
from twisted.internet import reactor
call = reactor.callLater(2, reactor.crash)
result = self.runTest('test_calledButNeverCallback')
if call.active():
call.cancel()
self.failIf(result.wasSuccessful())
self.failUnlessEqual(len(result.errors), 1)
self._wasTimeout(result.errors[0][1])
示例10: _run
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import crash [as 别名]
def _run(self, methodName, result):
from twisted.internet import reactor
timeout = self.getTimeout()
def onTimeout(d):
e = defer.TimeoutError("%r (%s) still running at %s secs"
% (self, methodName, timeout))
f = failure.Failure(e)
# try to errback the deferred that the test returns (for no gorram
# reason) (see issue1005 and test_errorPropagation in test_deferred)
try:
d.errback(f)
except defer.AlreadyCalledError:
# if the deferred has been called already but the *back chain is
# still unfinished, crash the reactor and report timeout error
# ourself.
reactor.crash()
self._timedOut = True # see self._wait
todo = self.getTodo()
if todo is not None and todo.expected(f):
result.addExpectedFailure(self, f, todo)
else:
result.addError(self, f)
if self._shared:
test = self.__class__._testCaseInstance
else:
test = self
method = getattr(test, methodName)
d = defer.maybeDeferred(utils.runWithWarningsSuppressed,
self.getSuppress(), method)
call = reactor.callLater(timeout, onTimeout, d)
d.addBoth(lambda x : call.active() and call.cancel() or x)
return d
示例11: writeSomething
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import crash [as 别名]
def writeSomething(self):
if self.disconnected:
if not self.finished:
self.fail()
else:
reactor.crash()
if not self.disconnected:
self.transport.write('foo')
reactor.callLater(1, self.writeSomething)
示例12: crash
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import crash [as 别名]
def crash(self):
reactor.crash()
示例13: testIterate
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import crash [as 别名]
def testIterate(self):
"""Test that reactor.iterate(0) doesn't block"""
start = time.time()
# twisted timers are distinct from the underlying event loop's
# timers, so this fail-safe probably won't keep a failure from
# hanging the test
t = reactor.callLater(10, self.crash)
reactor.iterate(0) # shouldn't block
stop = time.time()
elapsed = stop - start
#print "elapsed", elapsed
self.failUnless(elapsed < 8)
t.cancel()
示例14: destroy
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import crash [as 别名]
def destroy(self):
reactor.crash()
Tkinter.Frame.destroy(self)
#
# This class was written based on code from Drew "drewp" Pertulla
# (<drewp (at) bigasterisk (dot) com>) - without his help, tkmktap
# would be an ugly POS.
#
示例15: test
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import crash [as 别名]
def test(arguments):
arguments['test'] = True
reactor.crash()