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


Python Listener.stop方法代码示例

本文整理汇总了Python中listener.Listener.stop方法的典型用法代码示例。如果您正苦于以下问题:Python Listener.stop方法的具体用法?Python Listener.stop怎么用?Python Listener.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在listener.Listener的用法示例。


在下文中一共展示了Listener.stop方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: EmonHub

# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import stop [as 别名]
def EmonHub():
    
    # Load settings
    settings = ConfigObj("emonhub.conf", file_error=True)
    
    # Create queue for node packets
    queue = Queue.Queue(0)

    # Create and start serial listener
    a = Listener(queue,settings)
    a.start()
    
    # Create and start http dispatcher
    b = Dispatcher(queue,settings)
    b.start()

    while 1:
        try:
            time.sleep(0.1)
        except KeyboardInterrupt:
            print "Stopping threads"
            a.stop = True
            b.stop = True
            break
开发者ID:BuloZB,项目名称:development,代码行数:26,代码来源:03.py

示例2: print

# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import stop [as 别名]
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import logging.config

from config import config
from listener import Listener

logging.filename = 'logs/{}_log'.format(config['server_name'])
logging.config.fileConfig('logging.ini')

if __name__ == '__main__':
    if '-h' in sys.argv or '--help' in sys.argv:
        print('Run this file and as the first argument send name of the config'
              'file. For example: python main.py config.ini')

    if len(sys.argv) < 2:
        logging.error('Please specify config name.')
        sys.exit(1)

    listener = Listener()
    try:
        listener.start()
    except KeyboardInterrupt:
        logging.info('KeyboardInterrupt. Exiting...')
        listener.stop()
        listener.join()
开发者ID:alberand,项目名称:database,代码行数:30,代码来源:main.py

示例3: Trollduction

# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import stop [as 别名]

#.........这里部分代码省略.........
    def init_listener(self, address_list, msg_type_list):
        '''Initialise listener that receives messages about new files
        to be processed, etc.
        '''
        # Create Pipe connection
        parent_conn, child_conn = Pipe()
        self.listener_parent_conn = parent_conn
        self.listener_child_conn = child_conn

        # Create a Listener instance
        self.listener = Listener(address_list=address_list, 
                                 msg_type_list=msg_type_list, 
                                 pipe=self.listener_child_conn)
        #self.listener.add_address_list(address_list)
        #self.listener.type_list = msg_type_list

        # Create subscriber
        #self.listener.create_subscriber()
        print "Listener initialised"


    def start_listener(self):
        '''Start Listener instance into a new daemonized thread.
        '''
        self.listener_thread = Thread(target=self.listener.run)
        self.listener_thread.setDaemon(True)
        self.listener_thread.start()
        print "Listener started"


    def restart_listener(self):
        '''Restart listener
        '''
        self.listener.stop()
        self.init_listener()
        self.start_listener()


    def cleanup(self):
        '''Cleanup everything before shutdown
        '''
        # TODO: add cleanup, close threads, and stuff
        pass


    def shutdown(self):
        '''Shutdown trollduction
        '''
        self.cleanup()
        sys.exit()


    def run_single(self):
        '''Run image production without threading.
        '''
        # TODO: Get relevant preprocessing function for this
        #   production chain type: single/multi, or
        #   swath, geo, granule, global_polar, global_geo, global_mixed
        # That is, gatherer for the multi-image/multi-granule types
        # preproc_func = getattr(preprocessing, self.production_type)

        while True:
            # wait for new messages
            msg = self.listener_parent_conn.recv()
            print msg
            # shutdown trollduction
开发者ID:uservidya,项目名称:trollduction,代码行数:70,代码来源:trollduction.py

示例4: NetMgr

# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import stop [as 别名]
class NetMgr(Mgr):
    def __init__(self, engine,localOptions):
        Mgr.__init__(self, engine)
        self.engine = engine
        self.networkingEnabled = localOptions.enableNetworking
        if self.networkingEnabled:
            self.server = localOptions.server
        else:
            self.server = False
        self.ip = localOptions.ip
        self.remainingIDs = []
        self.timeToWaitForPlayers = 10

    def initialize(self):
        pass   
    def loadLevel(self):
        if self.networkingEnabled:
            self.broadcaster = Broadcaster()
            self.listener = Listener()
            self.listener.start()
            self.broadcaster.start()
        if self.server or not self.networkingEnabled:
            self.remainingIDs.append([1,""])
            self.remainingIDs.append([2,""])
    
    def releaseLevel(self):
        if self.networkingEnabled:
            self.listener.stop()
            self.broadcaster.stop()
            self.listener.join()
            self.broadcaster.join()

    def tick(self, dtime):
        if self.networkingEnabled:
            if dtime < 1 and self.timeToWaitForPlayers > 0:
                self.timeToWaitForPlayers -= dtime
            # check to see if all players are ready to start the race
            if self.timeToWaitForPlayers > 0 and self.engine.gameMgr.allPlayersReady == False:
                allReady = True
                for ent in self.engine.entMgr.entities:
                    if not ent.isReady:
                        allReady = False
                if len(self.engine.entMgr.entities) > 1:
                    self.engine.gameMgr.allPlayersReady = allReady
            elif self.timeToWaitForPlayers <= 0:
                self.engine.gameMgr.allPlayersReady = True

            # get messages
            incoming = self.listener.getMessages()
            outgoingMsgs = []
            for msgs in incoming:
                msgType, msg = messages.unpack(msgs)
                if msgType == const.STATUS:
                    found = False
                    # check to see if the status message is regarding a ship that is already created
                    for ent in self.engine.entMgr.entities:
                        if ent.shipId == msg.shipId:
                            found = True
                    # if it is, send updates to entity
                    if found and msg.shipId != self.engine.entMgr.playerIndex:
                        self.engine.entMgr.entities[msg.shipId].updateQueue.append(msg)
                    # if it isn't, create that entity
                    elif not found:
                        ent = Spaceship("Ship" + str(msg.shipId),msg.shipId, self.engine,const.MESHES[msg.shipId])
                        ent.pos = self.engine.entMgr.nextPos
                        self.engine.entMgr.nextPos.x += 40
                        self.engine.entMgr.entities.append(ent)
                # only process requests before game has started
                elif msgType == const.REQUEST and self.timeToWaitForPlayers > 0:
                    for ID in self.remainingIDs:
                        # if the id has not been issued already, or if the ID corresponds to a user who has been given an ID (but did not recieve their ID), send the ID
                        if ID[1] == "" or ID[1] ==  msg.userName:
                            outgoingMsgs.append(messages.pack(messages.InfoMessage(msg.userName,ID[0]),const.INFO))
                            ID[1] = msg.userName
                # only process info messages when this player has not been handed a playerIndex
                elif msgType == const.INFO and not self.server and self.engine.entMgr.playerIndex == -1:
                    self.engine.entMgr.playerIndex = msg.shipId
                    found = False
                    for ent in self.engine.entMgr.entities:
                        if ent.shipId == msg.shipId:
                            found = True
                    if not found:
                        ent = Spaceship("Ship" + str(msg.shipId),msg.shipId, self.engine,const.MESHES[msg.shipId])
                        ent.pos = self.engine.entMgr.nextPos
                        self.engine.entMgr.nextPos.x += 40
                        self.engine.entMgr.entities.append(ent)

            # if this player has not been handed a playerIndex, request one.
            if self.engine.entMgr.playerIndex == -1:
                outgoingMsgs.append(messages.pack(messages.RequestMessage(str(socket.gethostname())),const.REQUEST))
            # if the player has been handed a playerIndex, send the status of your ship
            else:
                myId = self.engine.entMgr.playerIndex
                myEnt = self.engine.entMgr.entities[myId]
                outgoingMsgs.append(messages.pack(messages.StatusMessage(myId,myEnt.pos,myEnt.dir,myEnt.colVel,myEnt.speed,myEnt.pitch, myEnt.roll,myEnt.isReady),const.STATUS))
            # send outgoing messages
            for msg in outgoingMsgs:
                self.broadcaster.addMessage(msg)
开发者ID:alexander-jones,项目名称:Saturn-Racing,代码行数:100,代码来源:netMgr.py


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