本文整理汇总了Python中twisted.internet.selectreactor.SelectReactor.stop方法的典型用法代码示例。如果您正苦于以下问题:Python SelectReactor.stop方法的具体用法?Python SelectReactor.stop怎么用?Python SelectReactor.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.selectreactor.SelectReactor
的用法示例。
在下文中一共展示了SelectReactor.stop方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stop
# 需要导入模块: from twisted.internet.selectreactor import SelectReactor [as 别名]
# 或者: from twisted.internet.selectreactor.SelectReactor import stop [as 别名]
def stop(self):
"""Stops the reactor."""
SelectReactor.stop(self)
# If this was called while the reactor was paused we have to resume in order for it to complete
if self.paused:
self.run()
# These need to be re-registered so that the PausingReactor can be safely restarted after a stop
self.addSystemEventTrigger('during', 'shutdown', self.crash)
self.addSystemEventTrigger('during', 'shutdown', self.disconnectAll)
示例2: ReactorSlaveController
# 需要导入模块: from twisted.internet.selectreactor import SelectReactor [as 别名]
# 或者: from twisted.internet.selectreactor.SelectReactor import stop [as 别名]
class ReactorSlaveController(object):
def __init__(self):
self.keepGoing = True
self.reactor = SelectReactor()
installReactor(self.reactor)
connection = self.reactor.connectTCP('localhost', 8000, factory)
self.reactor.startRunning()
self.futureCall = None
self.futureCallTimeout = None
pygame_test.prepare()
def iterate(self):
print 'in iterate'
self.reactor.runUntilCurrent()
self.reactor.doIteration(0)
#t2 = self.reactor.timeout()
#print 'timeout', t2
#t = self.reactor.running and t2
#self.reactor.doIteration(t)
def run(self):
clock = pygame.time.Clock()
self.reactor.callLater(20, stupidTest)
while self.keepGoing:
timeChange = clock.tick(FRAMES_PER_SECOND)
if self.futureCall:
self.futureCallTimeout -= timeChange
print 'future call in', self.futureCallTimeout
if self.futureCallTimeout <= 0:
self.futureCall()
self.futureCallTimeout = None
self.futureCall= None
retval = pygame_test.iterate()
if retval == False:
thingInControl.stop()
self.iterate()
def stop(self):
print 'stopping'
self.reactor.stop()
self.keepGoing = False
def callLater(self, when, fn):
self.futureCallTimeout = when*1000
self.futureCall = fn
print 'future call in', self.futureCallTimeout
示例3: __init__
# 需要导入模块: from twisted.internet.selectreactor import SelectReactor [as 别名]
# 或者: from twisted.internet.selectreactor.SelectReactor import stop [as 别名]
class ReactorSpinController:
STATE_STOPPED = 0
STATE_STARTED = 1
STATE_SHUTTING_DOWN = 2
def __init__(self, evManager):
self.state = ReactorSpinController.STATE_STOPPED
self.evManager = evManager
self.evManager.RegisterListener( self )
self.reactor = SelectReactor()
installReactor(self.reactor)
self.loopingCall = LoopingCall(self.FireTick)
#----------------------------------------------------------------------
def FireTick(self):
self.evManager.Post( TickEvent() )
#----------------------------------------------------------------------
def Run(self):
self.state = ReactorSpinController.STATE_STARTED
framesPerSecond = 10
interval = 1.0 / framesPerSecond
self.loopingCall.start(interval)
self.reactor.run()
#----------------------------------------------------------------------
def Stop(self):
print 'stopping the reactor'
self.state = ReactorSpinController.STATE_SHUTTING_DOWN
self.reactor.addSystemEventTrigger('after', 'shutdown',
self.onReactorStop)
self.reactor.stop()
#----------------------------------------------------------------------
def onReactorStop(self):
print 'reactor is now totally stopped'
self.state = ReactorSpinController.STATE_STOPPED
self.reactor = None
#----------------------------------------------------------------------
def Notify(self, event):
if isinstance( event, QuitEvent ):
self.Stop()
示例4: test_basic_subresources
# 需要导入模块: from twisted.internet.selectreactor import SelectReactor [as 别名]
# 或者: from twisted.internet.selectreactor.SelectReactor import stop [as 别名]
def test_basic_subresources(self):
"""
A basic WSGI app can be ran, with subresources
"""
temp_reactor = SelectReactor()
r = router.RouterWorkerSession(config=self.config,
reactor=temp_reactor)
# Open the transport
transport = FakeWAMPTransport(r)
r.onOpen(transport)
realm_config = {
u"name": u"realm1",
u'roles': []
}
r.start_router_realm(u"realm1", realm_config)
r.start_router_transport(
"component1",
{
u"type": u"web",
u"endpoint": {
u"type": u"tcp",
u"port": 8080
},
u"paths": {
u"/": {
"module": u"crossbar.worker.test.test_router",
"object": u"hello",
"type": u"wsgi"
},
u"json": {
"type": u"json",
"value": {}
}
}
})
# Make a request to the /json endpoint, which is technically a child of
# the WSGI app, but is not served by WSGI.
d = treq.get("http://localhost:8080/json", reactor=temp_reactor)
d.addCallback(treq.content)
d.addCallback(self.assertEqual, b"{}")
d.addCallback(lambda _: temp_reactor.stop())
def escape():
if temp_reactor.running:
temp_reactor.stop()
temp_reactor.callLater(1, escape)
temp_reactor.run()
return d
示例5: test_basic
# 需要导入模块: from twisted.internet.selectreactor import SelectReactor [as 别名]
# 或者: from twisted.internet.selectreactor.SelectReactor import stop [as 别名]
def test_basic(self):
"""
A basic WSGI app can be ran.
"""
temp_reactor = SelectReactor()
r = router.RouterController(config=self.config,
reactor=temp_reactor)
# Open the transport
transport = FakeWAMPTransport(r)
r.onOpen(transport)
realm_config = {
u"name": u"realm1",
u'roles': []
}
r.start_router_realm(u"realm1", realm_config)
r.start_router_transport(
u"component1",
{
u"type": u"web",
u"endpoint": {
u"type": u"tcp",
u"port": 8080
},
u"paths": {
u"/": {
"module": u"crossbar.worker.test.test_router",
"object": u"hello",
"type": u"wsgi"
}
}
})
# Make a request to the WSGI app.
d = treq.get("http://localhost:8080/", reactor=temp_reactor)
d.addCallback(treq.content)
d.addCallback(self.assertEqual, b"hello!")
d.addCallback(lambda _: temp_reactor.stop())
def escape():
if temp_reactor.running:
temp_reactor.stop()
temp_reactor.callLater(1, escape)
temp_reactor.run()
return d
示例6: NetworkServerView
# 需要导入模块: from twisted.internet.selectreactor import SelectReactor [as 别名]
# 或者: from twisted.internet.selectreactor.SelectReactor import stop [as 别名]
class NetworkServerView(pb.Root):
"""We SEND events to the server through this object"""
STATE_PREPARING = 0
STATE_CONNECTING = 1
STATE_CONNECTED = 2
STATE_DISCONNECTING = 3
STATE_DISCONNECTED = 4
#----------------------------------------------------------------------
def __init__(self, evManager, sharedObjectRegistry):
self.evManager = evManager
self.evManager.RegisterListener( self )
self.pbClientFactory = pb.PBClientFactory()
self.state = NetworkServerView.STATE_PREPARING
self.reactor = None
self.server = None
self.sharedObjs = sharedObjectRegistry
#----------------------------------------------------------------------
def AttemptConnection(self):
print "attempting a connection to", serverHost, serverPort
self.state = NetworkServerView.STATE_CONNECTING
if self.reactor:
self.reactor.stop()
self.PumpReactor()
else:
self.reactor = SelectReactor()
installReactor(self.reactor)
connection = self.reactor.connectTCP(serverHost, serverPort,
self.pbClientFactory)
# TODO: make this anonymous login()
#deferred = self.pbClientFactory.login(credentials.Anonymous())
userCred = credentials.UsernamePassword(avatarID, 'pass1')
controller = NetworkServerController( self.evManager )
deferred = self.pbClientFactory.login(userCred, client=controller)
deferred.addCallback(self.Connected)
deferred.addErrback(self.ConnectFailed)
self.reactor.startRunning()
#----------------------------------------------------------------------
def Disconnect(self):
print "disconnecting"
if not self.reactor:
return
print 'stopping the reactor'
self.reactor.stop()
self.PumpReactor()
self.state = NetworkServerView.STATE_DISCONNECTING
#----------------------------------------------------------------------
def Connected(self, server):
print "CONNECTED"
self.server = server
self.state = NetworkServerView.STATE_CONNECTED
ev = ServerConnectEvent( server )
self.evManager.Post( ev )
#----------------------------------------------------------------------
def ConnectFailed(self, server):
print "CONNECTION FAILED"
print server
print 'quitting'
self.evManager.Post( QuitEvent() )
#self.state = NetworkServerView.STATE_PREPARING
self.state = NetworkServerView.STATE_DISCONNECTED
#----------------------------------------------------------------------
def PumpReactor(self):
self.reactor.runUntilCurrent()
self.reactor.doIteration(0)
#----------------------------------------------------------------------
def Notify(self, event):
NSV = NetworkServerView
if isinstance( event, TickEvent ):
if self.state == NSV.STATE_PREPARING:
self.AttemptConnection()
elif self.state in [NSV.STATE_CONNECTED,
NSV.STATE_DISCONNECTING,
NSV.STATE_CONNECTING]:
self.PumpReactor()
return
if isinstance( event, QuitEvent ):
self.Disconnect()
return
ev = event
if not isinstance( event, pb.Copyable ):
evName = event.__class__.__name__
copyableClsName = "Copyable"+evName
if not hasattr( network, copyableClsName ):
return
copyableClass = getattr( network, copyableClsName )
#NOTE, never even construct an instance of an event that
# is serverToClient, as a side effect is often adding a
# key to the registry with the local id().
if copyableClass not in network.clientToServerEvents:
#.........这里部分代码省略.........
示例7: test_root_not_required
# 需要导入模块: from twisted.internet.selectreactor import SelectReactor [as 别名]
# 或者: from twisted.internet.selectreactor.SelectReactor import stop [as 别名]
def test_root_not_required(self):
"""
Not including a '/' path will mean that path has a 404, but children
will still be routed correctly.
"""
temp_reactor = SelectReactor()
r = router.RouterWorkerSession(config=self.config,
reactor=temp_reactor)
# Open the transport
transport = FakeWAMPTransport(r)
r.onOpen(transport)
realm_config = {
u"name": u"realm1",
u'roles': []
}
# Make a file
with open(os.path.join(self.cbdir, 'file.txt'), "wb") as f:
f.write(b"hello!")
r.start_router_realm(u"realm1", realm_config)
r.start_router_transport(
u"component1",
{
u"type": u"web",
u"endpoint": {
u"type": u"tcp",
u"port": 8080
},
u"paths": {
u"static": {
u"directory": u".",
u"type": u"static"
}
}
})
d1 = treq.get("http://localhost:8080/", reactor=temp_reactor)
d1.addCallback(lambda resp: self.assertEqual(resp.code, 404))
d2 = treq.get("http://localhost:8080/static/file.txt",
reactor=temp_reactor)
d2.addCallback(treq.content)
d2.addCallback(self.assertEqual, b"hello!")
def done(results):
for item in results:
if not item[0]:
return item[1]
d = defer.DeferredList([d1, d2])
d.addCallback(done)
d.addCallback(lambda _: temp_reactor.stop())
def escape():
if temp_reactor.running:
temp_reactor.stop()
temp_reactor.callLater(1, escape)
temp_reactor.run()
示例8: NetworkServerView
# 需要导入模块: from twisted.internet.selectreactor import SelectReactor [as 别名]
# 或者: from twisted.internet.selectreactor.SelectReactor import stop [as 别名]
class NetworkServerView(pb.Root):
"""We SEND events to the server through this object"""
STATE_PREPARING = 0
STATE_CONNECTING = 1
STATE_CONNECTED = 2
STATE_DISCONNECTING = 3
STATE_DISCONNECTED = 4
#----------------------------------------------------------------------
def __init__(self, evManager, sharedObjectRegistry):
self.evManager = evManager
self.evManager.RegisterListener( self )
self.pbClientFactory = pb.PBClientFactory()
self.state = NetworkServerView.STATE_PREPARING
self.reactor = None
self.server = None
self.sharedObjs = sharedObjectRegistry
#----------------------------------------------------------------------
def AttemptConnection(self):
print "attempting a connection to", serverHost, serverPort
self.state = NetworkServerView.STATE_CONNECTING
if self.reactor:
self.reactor.stop()
self.PumpReactor()
else:
self.reactor = SelectReactor()
installReactor(self.reactor)
connection = self.reactor.connectTCP(serverHost, serverPort,
self.pbClientFactory)
deferred = self.pbClientFactory.getRootObject()
deferred.addCallback(self.Connected)
deferred.addErrback(self.ConnectFailed)
self.reactor.startRunning()
#----------------------------------------------------------------------
def Disconnect(self):
print "disconnecting"
if not self.reactor:
return
print 'stopping the reactor'
self.reactor.stop()
self.PumpReactor()
self.state = NetworkServerView.STATE_DISCONNECTING
#----------------------------------------------------------------------
def Connected(self, server):
print "CONNECTED"
self.server = server
self.state = NetworkServerView.STATE_CONNECTED
ev = ServerConnectEvent( server )
self.evManager.Post( ev )
#----------------------------------------------------------------------
def ConnectFailed(self, server):
print "CONNECTION FAILED"
#self.state = NetworkServerView.STATE_PREPARING
self.state = NetworkServerView.STATE_DISCONNECTED
#----------------------------------------------------------------------
def PumpReactor(self):
self.reactor.runUntilCurrent()
self.reactor.doIteration(0)
#----------------------------------------------------------------------
def Notify(self, event):
NSV = NetworkServerView
if isinstance( event, TickEvent ):
if self.state == NSV.STATE_PREPARING:
self.AttemptConnection()
elif self.state in [NSV.STATE_CONNECTED,
NSV.STATE_DISCONNECTING,
NSV.STATE_CONNECTING]:
self.PumpReactor()
return
if isinstance( event, QuitEvent ):
self.Disconnect()
return
ev = event
if not isinstance( event, pb.Copyable ):
evName = event.__class__.__name__
copyableClsName = "Copyable"+evName
if not hasattr( network, copyableClsName ):
return
copyableClass = getattr( network, copyableClsName )
ev = copyableClass( event, self.sharedObjs )
if ev.__class__ not in network.clientToServerEvents:
#print "CLIENT NOT SENDING: " +str(ev)
return
if self.server:
print " ==== Client sending", str(ev)
remoteCall = self.server.callRemote("EventOverNetwork",
ev)
else:
#.........这里部分代码省略.........