def run(self):
        try:
            self._deque_condition.acquire()
            while not self._stop_requested:
                if len(self._deque) == 0:
                    self._deque_condition.wait()
                    continue

                outgoing_data = self._deque.popleft()

                self._deque_condition.release()
                self._write_data(outgoing_data)
                self._deque_condition.acquire()

            # Flush deque.
            #
            # At this point, self._deque_condition is always acquired.
            try:
                while len(self._deque) > 0:
                    outgoing_data = self._deque.popleft()
                    self._write_data(outgoing_data)
            finally:
                self._deque_condition.release()

            # Close physical connection.
            try:
                # Don't wait the response here. The response will be read
                # by the reader thread.
                self._mux_handler.physical_stream.close_connection(
                    self._close_code, wait_response=False)
            except Exception, e:
                util.prepend_message_to_exception(
                    'Failed to close the physical connection: %r' % e)
                raise
        finally:
            self._mux_handler.notify_writer_done()
dataset/ETHPy150Open google/pywebsocket/mod_pywebsocket/mux.py/_PhysicalConnectionWriter.run/original