def deamon_command(command, timer, debug, time_out, is_daemon): wk = Work(timer=timer, pid_file=PID_FILE, debug=debug, time_out=time_out, is_daemon=is_daemon) if command == DAEMON_START: wk.start() elif command == DAEMON_STOP: wk.stop() elif command == DAEMON_RESTART: wk.stop() time.sleep(3) wk.start()
def accept(self): # 持续监听端口 while True: # 获得新连接客户机的数据 client, address = self.server.accept() print("检测到新的连接,ip:{},端口:{}".format(address[0], address[1])) # 更新用户列表 self.clients.append({ "client": client, "username": "", "status": "connect" }) # 创建子线程处理本次连接 t = Work(self.update_clients, client, self.db) # 将该线程加入线程列表 self.threads.append(t) # 开始子线程 t.start()