'Ensure the writer has stopped, wait to see if it does.'

def stop(self, timeout=None):

    self.connection_stopped.wait(timeout)
    if self._connection_routine:
        self._connection_routine.join()
        self._connection_routine = None
    return self.connection_stopped.is_set()
