当前位置: 首页>>代码示例>>Python>>正文


Python SelectReactor.addSystemEventTrigger方法代码示例

本文整理汇总了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()
开发者ID:ClashTeak,项目名称:writing_games_tutorial,代码行数:45,代码来源:client.py


注:本文中的twisted.internet.selectreactor.SelectReactor.addSystemEventTrigger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。