def run(self):
        """Combine async uwsgi message loop with ws4py message loop.

        TODO: This could do some serious optimizations and behave asynchronously correct instead of just sleep().
        """

        self.sock.setblocking(False)
        try:
            while not self.terminated:
                logger.debug("Doing nothing")
                time.sleep(0.050)

                logger.debug("Asking for downstream msg")
                msg = uwsgi.websocket_recv_nb()
                if msg:
                    logger.debug("Incoming downstream WS: %s", msg)
                    self.send(msg)

                s = self.stream

                self.opened()

                logger.debug("Asking for upstream msg {s}".format(s=s))
                try:
                    bytes = self.sock.recv(self.reading_buffer_size)
                    if bytes:
                        self.process(bytes)
                except BlockingIOError:
                    pass

        except Exception as e:
            logger.exception(e)
        finally:
            logger.info("Terminating WS proxy loop")
            self.terminate()
def run ( self ) : self . sock . setblocking ( False ) try : while not self . terminated : logger . debug ( "Doing nothing" ) time . sleep ( 0.050 ) logger . debug ( "Asking for downstream msg" ) msg = uwsgi . websocket_recv_nb ( ) if msg : logger . debug ( "Incoming downstream WS: %s" , msg ) self . send ( msg ) s = self . stream self . opened ( ) logger . debug ( "Asking for upstream msg {s}" . format ( s = s ) ) try : bytes = self . sock . recv ( self . reading_buffer_size ) if bytes : self . process ( bytes ) except BlockingIOError : pass except Exception as e : logger . exception ( e ) finally : logger . info ( "Terminating WS proxy loop" ) self . terminate ( )
Combine async uwsgi message loop with ws4py message loop.

        TODO: This could do some serious optimizations and behave asynchronously correct instead of just sleep().