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


Python Listener.serve_forever方法代码示例

本文整理汇总了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()
开发者ID:MattHung,项目名称:sage-graphics,代码行数:39,代码来源:dim.py

示例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()
开发者ID:Vadiza,项目名称:sage-3.5b,代码行数:67,代码来源:dim.py


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