當前位置: 首頁>>代碼示例>>Python>>正文


Python geventwebsocket.WebSocketError方法代碼示例

本文整理匯總了Python中geventwebsocket.WebSocketError方法的典型用法代碼示例。如果您正苦於以下問題:Python geventwebsocket.WebSocketError方法的具體用法?Python geventwebsocket.WebSocketError怎麽用?Python geventwebsocket.WebSocketError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在geventwebsocket的用法示例。


在下文中一共展示了geventwebsocket.WebSocketError方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_events

# 需要導入模塊: import geventwebsocket [as 別名]
# 或者: from geventwebsocket import WebSocketError [as 別名]
def get_events(self, ws):
        """
        Yields valid messages from the websocket. Only yields well formed
        messages. In the case of an illformed message, an error event is sent
        to the client.
        """
        while True:
            try:
                raw = ws.receive()
            except WebSocketError:
                return
            try:
                event = json.loads(raw)
                event['e']
            except (ValueError, TypeError) as v:
                self.send_error(ws, 'event', str(v))
                return
            except KeyError:
                self.send_error(ws, 'event', "No 'e' field sent")
                return

            yield event 
開發者ID:quantopian,項目名稱:qdb,代碼行數:24,代碼來源:client.py

示例2: do_install

# 需要導入模塊: import geventwebsocket [as 別名]
# 或者: from geventwebsocket import WebSocketError [as 別名]
def do_install(self, ws, message):
        def go_do_install():
            with tempfile.NamedTemporaryFile() as f:
                f.write(message)
                f.flush()
                try:
                    self.load_pbws([f.name], cache=True)
                    AppInstaller(self.pebble.pebble, f.name, blobdb_client=self.pebble.blobdb).install()
                except:
                    try:
                        ws.send(bytearray([0x05, 0x00, 0x00, 0x00, 0x01]))
                    except WebSocketError:
                        pass
                    raise
                else:
                    try:
                        ws.send(bytearray([0x05, 0x00, 0x00, 0x00, 0x00]))
                    except WebSocketError:
                        pass
        gevent.spawn(go_do_install) 
開發者ID:pebble,項目名稱:pypkjs,代碼行數:22,代碼來源:websocket.py

示例3: progress_sender

# 需要導入模塊: import geventwebsocket [as 別名]
# 或者: from geventwebsocket import WebSocketError [as 別名]
def progress_sender(job, channel, interval=5, stat=None):

    stat = stat or (lambda data: data)
    data = job.data

    i = 10
    try:
        while True:
            # if thread died due to some reason, still send 10 stats
            if not job.thread.is_alive():
                logger.info('job %s died: %s' % (job.ident, repr(job.err)))
                if i == 0:
                    channel.ws.close()
                    break
                i -= 1

            logger.info('jod %s on channel %s send progress: %s' %
                        (job.ident, repr(channel), repr(stat(data))))

            to_send = stat(data)
            if channel.report_system_load and type(to_send) == type({}):
                to_send['system_load'] = channel.get_system_load()

            channel.ws.send(utfjson.dump(to_send))

            if job.progress_available.wait(interval):
                job.progress_available.clear()

    except WebSocketError as e:
        if channel.ws.closed == True:
            logger.info('the client has closed the connection')
        else:
            logger.exception(('got websocket error when sending progress on' +
                              ' channel %s: %s') % (repr(channel), repr(e)))

    except Exception as e:
        logger.exception('got exception when sending progress on channel %s: %s'
                         % (repr(channel), repr(e)))
        channel.ws.close() 
開發者ID:bsc-s2,項目名稱:pykit,代碼行數:41,代碼來源:wsjobd.py

示例4: send_error

# 需要導入模塊: import geventwebsocket [as 別名]
# 或者: from geventwebsocket import WebSocketError [as 別名]
def send_error(self, ws, error_type, error_data):
        """
        Sends an error event back to the client.
        """
        try:
            ws.send(fmt_err_msg(error_type, error_data, serial=json.dumps))
        except WebSocketError:
            return 
開發者ID:quantopian,項目名稱:qdb,代碼行數:10,代碼來源:client.py

示例5: slaughter

# 需要導入模塊: import geventwebsocket [as 別名]
# 或者: from geventwebsocket import WebSocketError [as 別名]
def slaughter(self, uuid, mode='soft'):
        """
        Slaughters a session, closing all clients and the tracer.
        This also removes the session from the list of sessions.
        If mode is 'soft', the tracer clears all breakpoints and continues
        execution. If it is 'hard', it raises a QdbQuit in the tracer process.
        """
        session = self._sessions.get(uuid)
        if not session:
            return  # Slaughtering a session that does not exits.
        # Close all the clients.
        disable_event = fmt_msg('disable')
        self.send_to_clients(uuid, event=disable_event)
        for client in session.clients:
            try:
                client.close()
            except WebSocketError as e:
                if str(e) != 'Socket is dead' or e.errno not in safe_errnos:
                    log.exception(
                        'Exception caught while killing client for '
                        'session %s:' % uuid
                    )
        # Close the tracer if we had one.
        if session.tracer:
            try:
                disable_event['p'] = mode
                self.send_to_tracer(uuid, event=disable_event)
                session.tracer.close()
            except socket.error as e:
                if e.errno not in safe_errnos:
                    log.exception(
                        'Exception caught while killing tracer for session %s:'
                        % uuid
                    )
        del self._sessions[uuid]
        log.info('Debugging session %s has been terminated' % uuid) 
開發者ID:quantopian,項目名稱:qdb,代碼行數:38,代碼來源:session_store.py

示例6: data_socket

# 需要導入模塊: import geventwebsocket [as 別名]
# 或者: from geventwebsocket import WebSocketError [as 別名]
def data_socket(ws):
    data = 0
    while True:
        try:
            ws.send('Some Data: %d' % data)
        except WebSocketError as e:
            print('Caught WebSocketError: %s' % e)
            break
        sleep(2)
        data += 1 
開發者ID:ResEnv,項目名稱:chain-api,代碼行數:12,代碼來源:server.py

示例7: handle_ws

# 需要導入模塊: import geventwebsocket [as 別名]
# 或者: from geventwebsocket import WebSocketError [as 別名]
def handle_ws(self, environ, start_response):
        if environ['PATH_INFO'] == '/':
            ws = Websocket(environ['wsgi.websocket'])
            self.websockets.append(ws)
            self.on_open(ws)
            while True:
                try:
                    self.on_message(ws, ws.receive())
                except WebSocketError:
                    break
            self.on_close(ws) 
開發者ID:pebble,項目名稱:pypkjs,代碼行數:13,代碼來源:websocket.py

示例8: broadcast

# 需要導入模塊: import geventwebsocket [as 別名]
# 或者: from geventwebsocket import WebSocketError [as 別名]
def broadcast(self, message):
        to_remove = []
        for i, ws in enumerate(self.websockets):
            if ws.authed:
                try:
                    ws.send(message)
                except (WebSocketError, ssl.SSLError):
                    to_remove.append(i)
        for i in reversed(to_remove):
            del self.websockets[i]

    # https://pebbletechnology.atlassian.net/wiki/pages/viewpage.action?pageId=491742 
開發者ID:pebble,項目名稱:pypkjs,代碼行數:14,代碼來源:websocket.py

示例9: do_phone_info

# 需要導入模塊: import geventwebsocket [as 別名]
# 或者: from geventwebsocket import WebSocketError [as 別名]
def do_phone_info(self, ws, message):
        try:
            ws.send(bytearray("\x06pypkjs,0.0.0,qemu"))
        except WebSocketError:
            pass 
開發者ID:pebble,項目名稱:pypkjs,代碼行數:7,代碼來源:websocket.py

示例10: get_realtime_tlm

# 需要導入模塊: import geventwebsocket [as 別名]
# 或者: from geventwebsocket import WebSocketError [as 別名]
def get_realtime_tlm(self):
        """Handles realtime packet dispatch via websocket layers"""
        pad = bytearray(1)
        websocket = bottle.request.environ.get('wsgi.websocket')

        if not websocket:
            bottle.abort(400, 'Expected WebSocket request.')

        empty_map = dict()  # default empty object for probing websocket connection

        req_env = bottle.request.environ
        client_ip = req_env.get('HTTP_X_FORWARDED_FOR') or req_env.get('REMOTE_ADDR') or "(unknown)"
        self.dbg_message('Creating a new web-socket session with client IP '+client_ip)

        try:
            while not websocket.closed:
                try:
                    self.dbg_message("Polling Telemtry queue...")
                    uid, data = self._tlmQueue.popleft(timeout=30)
                    pkt_defn = self._get_tlm_packet_def(uid)
                    if not pkt_defn:
                        continue

                    pkt_name = pkt_defn.name

                    ait_pkt = ait.core.tlm.Packet(pkt_defn, data=data)

                    openmct_pkt = self.format_tlmpkt_for_openmct(ait_pkt)

                    openmct_pkt_jsonstr = json.dumps(openmct_pkt, default=self.datetime_jsonifier)

                    self.dbg_message("Sending realtime telemtry websocket msg: "+openmct_pkt_jsonstr)

                    websocket.send(openmct_pkt_jsonstr)

                except IndexError:
                    # If no telemetry has been received by the GUI
                    # server after timeout seconds, "probe" the client
                    # websocket connection to make sure it's still
                    # active and if so, keep it alive.  This is
                    # accomplished by sending an empty JSON object.
                    self.dbg_message("Telemtry queue is empty.")

                    if not websocket.closed:
                        websocket.send(json.dumps(empty_map))

            self.dbg_message('Web-socket session closed with client IP '+client_ip)

        except geventwebsocket.WebSocketError as wser:
            log.warn('Web-socket session had an error with client IP '+client_ip+': '+str(wser)) 
開發者ID:NASA-AMMOS,項目名稱:AIT-Core,代碼行數:52,代碼來源:openmct.py

示例11: handle_client

# 需要導入模塊: import geventwebsocket [as 別名]
# 或者: from geventwebsocket import WebSocketError [as 別名]
def handle_client(self, environ, start_response):
        path = environ['PATH_INFO']
        ws = environ['wsgi.websocket']
        addr = environ['REMOTE_ADDR']

        try:
            match = self.route.match(path)
            if not match:
                # This did not match our route.
                return
            log.info('Client request from %s' % addr)
            uuid = match.group(1)
            start_event = None
            with Timeout(self.auth_timeout, False):
                start_event = self.get_event(ws)

            failed = False
            message = ''

            # Fall through the various ways to fail to generate a more helpful
            # error message.
            if not start_event:
                message = 'No start event received'
                failed = True
            elif start_event['e'] != 'start':
                message = "First event must be of type: 'start'"
                failed = True
            elif not self.auth_fn(start_event.get('p', '')):
                log.warn('Client %s failed to authenticate' % addr)
                message = 'Authentication failed'
                failed = True

            if failed:
                try:
                    self.send_error(ws, 'auth', message)
                    ws.send(fmt_msg('disable', serial=json.dumps))
                except WebSocketError:
                    # We are unable to send the disable message for some
                    # reason; however, they already failed auth so suppress
                    # it and close.
                    pass
                return

            if not self.session_store.attach_client(uuid, ws):
                # We are attaching to a client that does not exist.
                return

            self.session_store.send_to_tracer(uuid, event=start_event)
            for event in self.get_events(ws):
                self.session_store.send_to_tracer(uuid, event=event)

        finally:
            log.info('Closing websocket to client %s' % addr)
            ws.close() 
開發者ID:quantopian,項目名稱:qdb,代碼行數:56,代碼來源:client.py


注:本文中的geventwebsocket.WebSocketError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。