<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def shutdown(self, wait=False):
 """ Arrange for the context to receive a ``SHUTDOWN`` message, triggering graceful shutdown. Due to a lack of support for timers, no attempt is made yet to force terminate a hung context using this method. This will be fixed shortly. :param bool wait: If :data:`True`, block the calling thread until the context has completely terminated. :returns: If `wait` is :data:`False`, returns a :class:`mitogen.core.Latch` whose :meth:`get() <mitogen.core.Latch.get>` method returns :data:`None` when shutdown completes. The `timeout` parameter may be used to implement graceful timeouts. """

        LOG.debug('%r.shutdown() sending SHUTDOWN', self)
        latch = mitogen.core.Latch()
        mitogen.core.listen(self, 'disconnect', lambda: latch.put(None))
        self.send(
            mitogen.core.Message(
                handle=mitogen.core.SHUTDOWN,
            )
        )

        if wait:
            latch.get()
        else:
            return latch