本文整理汇总了Python中listener.Listener.serve_forever方法的典型用法代码示例。如果您正苦于以下问题:Python Listener.serve_forever方法的具体用法?Python Listener.serve_forever怎么用?Python Listener.serve_forever使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类listener.Listener
的用法示例。
在下文中一共展示了Listener.serve_forever方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import serve_forever [as 别名]
class DIM:
def __init__(self, host, port):
# sageGate is the network connection with SAGE
self.sageGate = SageGate()
setSageGate(self.sageGate)
# the event manager takes care of properly dispatching events
self.evtMgr = EventManager()
setEvtMgr(self.evtMgr)
self.evtMgr.addHandlers()
# sageData keeps the current state of the SAGE windows/apps
self.sageData = SageData()
setSageData(self.sageData)
# overlay manager creates, destroys and updates overlays
self.overlayMgr = OverlayManager()
setOverlayMgr(self.overlayMgr)
# contains all the devices and takes care of loading plugins for them
# also, distributes HW messages to each device
self.devMgr = DeviceManager()
setDevMgr(self.devMgr)
# connect to SAGE
for i in range(5): # try to connect to SAGE for 5 seconds
if self.sageGate.connectToSage(host, port) != 0:
self.sageGate.registerSage()
break
time.sleep(1)
else: # we didn't manage to connect to sage in 5 seconds... so quit
exitApp()
# start listening for the device events
time.sleep(2) # wait till all the messages come in
self.listener = Listener(LISTENER_PORT, self.devMgr.onHWMessage)
self.listener.serve_forever()
示例2: __init__
# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import serve_forever [as 别名]
class DIM:
def __init__(self, host, port, loadState, autosave, doLog):
print "\n\n========= Starting DIM ============\n"
# the log object
if doLog:
setLog(Log())
print "Logging user interaction into: ", getLog().getLogFilename(), "\n\n"
# sageGate is the network connection with SAGE
self.sageGate = SageGate()
setSageGate(self.sageGate)
# the event manager takes care of properly dispatching events
self.evtMgr = EventManager()
setEvtMgr(self.evtMgr)
self.evtMgr.addHandlers()
# sageData keeps the current state of the SAGE windows/apps
self.sageData = SageData(autosave, self.sageGate)
setSageData(self.sageData)
# overlay manager creates, destroys and updates overlays
self.overlayMgr = OverlayManager()
setOverlayMgr(self.overlayMgr)
# contains all the devices and takes care of loading plugins for them
# also, distributes HW messages to each device
self.devMgr = DeviceManager()
setDevMgr(self.devMgr)
# connect to SAGE
if (DEBUG):
print "\n\nRUNNING IN DEBUG MODE!!!!\n\n"
else:
time.sleep(2)
for i in range(20): # try to connect to SAGE for X seconds
retval = self.sageGate.connectToSage(host, port)
if retval == 1:
self.sageGate.registerSage("dim")
print "DIM: successfully connected to SAGE", (host, port)
break
elif retval == 0:
print "DIM: SAGE", (host, port), "is not ready yet. Retrying..."
elif retval == -1:
print "DIM: Couldn't connect to appLauncher. appLauncher is not ready yet. Retrying..."
time.sleep(1)
else: # we didn't manage to connect to sage in X seconds... so quit
exitApp()
# start listening for the device events
time.sleep(2) # wait till all the messages come in
self.overlayMgr._addGlobalOverlays() # add all the UI plugins for the display
# automatically load a saved state if so desired
if loadState:
print "\n===> Autoloading state: ", loadState, "\n"
t = Timer(3, self.sageData.loadState, [loadState])
t.start()
self.listener = Listener(LISTENER_PORT, self.devMgr.onHWMessage)
self.listener.serve_forever()