本文整理汇总了Python中twisted.internet.selectreactor.SelectReactor.addSystemEventTrigger方法的典型用法代码示例。如果您正苦于以下问题:Python SelectReactor.addSystemEventTrigger方法的具体用法?Python SelectReactor.addSystemEventTrigger怎么用?Python SelectReactor.addSystemEventTrigger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.selectreactor.SelectReactor
的用法示例。
在下文中一共展示了SelectReactor.addSystemEventTrigger方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from twisted.internet.selectreactor import SelectReactor [as 别名]
# 或者: from twisted.internet.selectreactor.SelectReactor import addSystemEventTrigger [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()