def METHOD_NAME(self, timeout=None):
    """Flush existing messages and then close comm
    If set, raises `tornado.util.TimeoutError` after a timeout.
    """
    if self.comm is None:
        return
    self.please_stop = True
    self.waker.set()
    yield self.stopped.wait(timeout=timeout)
    if not self.comm.closed():
        try:
            if self.buffer:
                self.buffer, payload = [], self.buffer
                # See note in `_background_send` for explanation of `closing`.
                with contextlib.closing(
                    self.comm.write(
                        payload, serializers=self.serializers, on_error="raise"
                    )
                ) as coro:
                    yield coro
        except CommClosedError:
            pass
        yield self.comm.METHOD_NAME()