Python tornado.websocket 模块,WebSocketClosedError() 实例源码

我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用tornado.websocket.WebSocketClosedError()

项目:geekcloud    作者:GeekCloud-Team    | 项目源码 | 文件源码
def open(self):
        # ?????path
        self.file_path = self.get_argument('file_path', '')
        MonitorHandler.clients.append(self)
        thread = MyThread(target=file_monitor, args=('%s.log' % self.file_path, self))
        MonitorHandler.threads.append(thread)
        self.stream.set_nodelay(True)

        try:
            for t in MonitorHandler.threads:
                if t.is_alive():
                    continue
                t.setDaemon(True)
                t.start()

        except WebSocketClosedError:
            client_index = MonitorHandler.clients.index(self)
            MonitorHandler.threads[client_index].stop()
            MonitorHandler.clients.remove(self)
            MonitorHandler.threads.remove(MonitorHandler.threads[client_index])

        logger.debug("Websocket: Monitor client num: %s, thread num: %s" % (len(MonitorHandler.clients),
                                                                            len(MonitorHandler.threads)))
项目:server    作者:sgr-smile2015    | 项目源码 | 文件源码
def open(self):
        # ?????path
        self.file_path = self.get_argument('file_path', '')
        MonitorHandler.clients.append(self)
        thread = MyThread(target=file_monitor, args=('%s.log' % self.file_path, self))
        MonitorHandler.threads.append(thread)
        self.stream.set_nodelay(True)

        try:
            for t in MonitorHandler.threads:
                if t.is_alive():
                    continue
                t.setDaemon(True)
                t.start()

        except WebSocketClosedError:
            client_index = MonitorHandler.clients.index(self)
            MonitorHandler.threads[client_index].stop()
            MonitorHandler.clients.remove(self)
            MonitorHandler.threads.remove(MonitorHandler.threads[client_index])

        logger.debug("Websocket: Monitor client num: %s, thread num: %s" % (len(MonitorHandler.clients),
                                                                            len(MonitorHandler.threads)))
项目:django-gateone    作者:jimmy201602    | 项目源码 | 文件源码
def _deliver(cls, message, upn="AUTHENTICATED", session=None):
        """
        Writes the given *message* (string) to all users matching *upn* using
        the write_message() function.  If *upn* is not provided or is
        "AUTHENTICATED", will send the *message* to all users.

        Alternatively a *session* ID may be specified instead of a *upn*.  This
        is useful when more than one user shares a UPN (i.e. ANONYMOUS).
        """
        #print 'deliver message',message
        logging.debug("_deliver(%s, upn=%s, session=%s)" %
            (message, upn, session))
        for instance in cls.instances:
            try: # Only send to users that have authenticated
                user = instance.current_user
            except (WebSocketClosedError, AttributeError):
                continue
            if session and user and user.get('session', None) == session:
                instance.write_message(message)
            elif upn == "AUTHENTICATED":
                instance.write_message(message)
            elif user and upn == user.get('upn', None):
                instance.write_message(message)
项目:jumpsever    作者:jacksonyoudi    | 项目源码 | 文件源码
def open(self):
        # ?????path
        self.file_path = self.get_argument('file_path', '')
        MonitorHandler.clients.append(self)
        thread = MyThread(target=file_monitor, args=('%s.log' % self.file_path, self))
        MonitorHandler.threads.append(thread)
        self.stream.set_nodelay(True)

        try:
            for t in MonitorHandler.threads:
                if t.is_alive():
                    continue
                t.setDaemon(True)
                t.start()

        except WebSocketClosedError:
            client_index = MonitorHandler.clients.index(self)
            MonitorHandler.threads[client_index].stop()
            MonitorHandler.clients.remove(self)
            MonitorHandler.threads.remove(MonitorHandler.threads[client_index])

        logger.debug("Websocket: Monitor client num: %s, thread num: %s" % (len(MonitorHandler.clients),
                                                                            len(MonitorHandler.threads)))
项目:board-games-app    作者:sampathweb    | 项目源码 | 文件源码
def send_message(self, action, **data):
        """Sends the message to the connected client
        """
        message = {
            "action": action,
            "data": data
        }
        try:
            self.write_message(json.dumps(message))
        except WebSocketClosedError:
            logger.warning("WS_CLOSED", "Could Not send Message: " + json.dumps(message))
            # Send Websocket Closed Error to Paired Opponent
            self.send_pair_message(action="pair-closed")
            self.close()
项目:geekcloud    作者:Mr-Linus    | 项目源码 | 文件源码
def run(self):
        try:
            super(MyThread, self).run()
        except WebSocketClosedError:
            pass
项目:geekcloud    作者:Mr-Linus    | 项目源码 | 文件源码
def open(self):
        # ?????path
        self.file_path = self.get_argument('file_path', '')
        MonitorHandler.clients.append(self)
        thread = MyThread(target=file_monitor, args=('%s.log' % self.file_path, self))
        MonitorHandler.threads.append(thread)
        self.stream.set_nodelay(True)

        try:
            for t in MonitorHandler.threads:
                if t.is_alive():
                    continue
                t.setDaemon(True)
                t.start()

        except WebSocketClosedError:
            client_index = MonitorHandler.clients.index(self)
            MonitorHandler.threads[client_index].stop()
            MonitorHandler.clients.remove(self)
            MonitorHandler.threads.remove(MonitorHandler.threads[client_index])

        logger.debug("Websocket: Monitor client num: %s, thread num: %s" % (len(MonitorHandler.clients),
                                                                            len(MonitorHandler.threads)))
项目:geekcloud    作者:GeekCloud-Team    | 项目源码 | 文件源码
def run(self):
        try:
            super(MyThread, self).run()
        except WebSocketClosedError:
            pass
项目:server    作者:sgr-smile2015    | 项目源码 | 文件源码
def run(self):
        try:
            super(MyThread, self).run()
        except WebSocketClosedError:
            pass
项目:reactive-architecture-python    作者:mendrugory    | 项目源码 | 文件源码
def send_to_the_client(self, data):
        try:
            self.write_message(data)
        except websocket.WebSocketClosedError as e:
            self.on_close()
项目:reactive-architecture-python    作者:mendrugory    | 项目源码 | 文件源码
def callback(self, channel, method, header, body):
        machine = method.routing_key.split(".")[0]
        data = json.loads(body.decode("utf-8"))
        data['machine'] = machine
        try:
            self.write_message(data)
        except websocket.WebSocketClosedError as e:
            self.on_close()
项目:jumpsever    作者:jacksonyoudi    | 项目源码 | 文件源码
def run(self):
        try:
            super(MyThread, self).run()
        except WebSocketClosedError:
            pass
项目:indri    作者:jbm9    | 项目源码 | 文件源码
def ka(self):
        # print "%d: Keepalive: %s" % (time.time(), str(self))
        try:
            self.write_message(self.KA)
            tornado.ioloop.IOLoop.instance().add_timeout(datetime.timedelta(seconds=2), self.ka)
        except websocket.WebSocketClosedError:
            pass
项目:bring_the_idea    作者:GrigoriyMikhalkin    | 项目源码 | 文件源码
def broadcast(self, message, channel, sender):
        subscribers = self.get_subscribers(channel)
        for subscriber in subscribers:
            if subscriber != sender:
                try:
                    subscriber.write_message(message)
                except WebSocketClosedError:
                    self.remove_subscriber(channel, subscriber)