本文整理汇总了Python中twisted.trial.util.spinWhile函数的典型用法代码示例。如果您正苦于以下问题:Python spinWhile函数的具体用法?Python spinWhile怎么用?Python spinWhile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spinWhile函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testBrokenTimer
def testBrokenTimer(self):
t = internet.TimerService(1, lambda: 1 / 0)
t.startService()
util.spinWhile(lambda :t._loop.running, timeout=30)
t.stopService()
self.assertEquals([ZeroDivisionError],
[o.value.__class__ for o in log.flushErrors(ZeroDivisionError)])
示例2: testTCP
def testTCP(self):
s = service.MultiService()
s.startService()
factory = protocol.ServerFactory()
factory.protocol = TestEcho
TestEcho.d = defer.Deferred()
t = internet.TCPServer(0, factory)
t.setServiceParent(s)
num = t._port.getHost().port
class Foo(basic.LineReceiver):
def connectionMade(self):
self.transport.write('lalala\r\n')
def lineReceived(self, line):
self.factory.line = line
self.transport.loseConnection()
factory = protocol.ClientFactory()
factory.protocol = Foo
factory.line = None
internet.TCPClient('127.0.0.1', num, factory).setServiceParent(s)
util.spinWhile(lambda :factory.line is None)
self.assertEqual(factory.line, 'lalala')
# Cleanup the reactor
util.wait(defer.maybeDeferred(s.stopService))
util.wait(TestEcho.d)
示例3: testClientBind
def testClientBind(self):
f = MyServerFactory()
p = reactor.listenTCP(0, f, interface="127.0.0.1")
self.ports.append(p)
factory = MyClientFactory()
reactor.connectTCP("127.0.0.1", p.getHost().port, factory,
bindAddress=("127.0.0.1", 0))
spinUntil(lambda :factory.protocol is not None)
self.assertEquals(factory.protocol.made, 1)
port = factory.protocol.transport.getHost().port
f2 = MyClientFactory()
reactor.connectTCP("127.0.0.1", p.getHost().port, f2,
bindAddress=("127.0.0.1", port))
spinUntil(lambda :f2.failed)
self.assertEquals(f2.failed, 1)
f2.reason.trap(error.ConnectBindError)
self.assert_(f2.reason.check(error.ConnectBindError))
self.assertEquals(f2.stopped, 1)
p.stopListening()
factory.protocol.transport.loseConnection()
spinWhile(lambda :p.connected)
self.assertEquals(factory.stopped, 1)
self.cleanPorts(*self.ports)
示例4: waitOnShutDown
def waitOnShutDown(self):
if not self.done:
try:
self.transport.signalProcess('KILL')
util.spinWhile(lambda: not self.done)
except error.ProcessExitedAlready:
pass
示例5: testSignal
def testSignal(self):
exe = sys.executable
scriptPath = util.sibpath(__file__, "process_signal.py")
signals = ("HUP", "INT", "KILL")
for sig in signals:
p = SignalProtocol(sig, self)
reactor.spawnProcess(p, exe, [exe, "-u", scriptPath, sig], env=None, usePTY=self.usePTY)
spinWhile(lambda: p.going)
self.failIf(p.failure, p.failure)
示例6: testUNIX
def testUNIX(self):
# FIXME: This test is far too dense. It needs comments.
# -- spiv, 2004-11-07
if not interfaces.IReactorUNIX(reactor, None):
raise unittest.SkipTest, "This reactor does not support UNIX domain sockets"
s = service.MultiService()
s.startService()
factory = protocol.ServerFactory()
factory.protocol = TestEcho
TestEcho.d = defer.Deferred()
t = internet.UNIXServer('echo.skt', factory)
t.setServiceParent(s)
class Foo(basic.LineReceiver):
def connectionMade(self):
self.transport.write('lalala\r\n')
def lineReceived(self, line):
self.factory.line = line
self.transport.loseConnection()
factory = protocol.ClientFactory()
factory.protocol = Foo
factory.line = None
internet.UNIXClient('echo.skt', factory).setServiceParent(s)
util.spinWhile(lambda :factory.line is None)
self.assertEqual(factory.line, 'lalala')
util.wait(defer.maybeDeferred(s.stopService))
util.wait(TestEcho.d)
TestEcho.d = defer.Deferred()
factory.line = None
s.startService()
util.spinWhile(lambda :factory.line is None)
self.assertEqual(factory.line, 'lalala')
# Cleanup the reactor
util.wait(defer.maybeDeferred(s.stopService))
util.wait(TestEcho.d)
示例7: cleanPorts
def cleanPorts(self, *ports):
for p in ports:
if p.connected:
p.loseConnection()
util.spinWhile(lambda :p.connected)
示例8: wait
def wait(self, sec_delay):
self.wake_up = time.time()+sec_delay
util.spinWhile(self._waiting, sec_delay+1)
示例9: wait
def wait(self, sec_delay):
wake_up = time.time() + sec_delay
def _waiting():
return time.time() < wake_up
util.spinWhile(_waiting, sec_delay+1)