本文整理汇总了Python中handler.Handler.start方法的典型用法代码示例。如果您正苦于以下问题:Python Handler.start方法的具体用法?Python Handler.start怎么用?Python Handler.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类handler.Handler
的用法示例。
在下文中一共展示了Handler.start方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Daemon
# 需要导入模块: from handler import Handler [as 别名]
# 或者: from handler.Handler import start [as 别名]
class Daemon(object):
def __init__(self, debug=False):
self.input = []
self.running = False
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.log = logger.Logger('server', debug=debug)
self.handler = Handler(self)
self._notify = pynotify.Notification('', '')
self._state = 'running'
def connect(self, arg=None):
try:
self.log.info('try connect server to port %s', cst.PORT)
self.socket.bind((socket.gethostname(), cst.PORT))
self.log.info('server started')
self.socket.listen(3)
self.running = True
self.input = [self.socket]
self.handler.start()
th = threading.Thread(target=self.start)
th.start()
self.notify('server started')
return ''
except socket.error, msg:
self.log.warning('connection failed: %s', str(msg))
return msg
示例2: run
# 需要导入模块: from handler import Handler [as 别名]
# 或者: from handler.Handler import start [as 别名]
def run(self):
while True:
try:
conn, addr = self.ssock.accept()
self.logger.debug("Client {} connected".format(utils.addr_to_ident(addr)))
hdl = Handler(conn, addr)
hdl.start()
except KeyboardInterrupt:
self.logger.critical("Interrupted by user. Exiting.")
self.ssock.shutdown(socket.SHUT_RDWR)
self.ssock.close()
sys.exit(0)