<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):
 """Shutdown ZAP."""

        if not self.is_running():
            self.logger.warn('ZAP is not running.')
            return

        self.logger.debug('Shutting down ZAP.')
        self.zap.core.shutdown()

        timeout_time = time.time() + self.timeout
        while self.is_running():
            if time.time() > timeout_time:
                raise ZAPError('Timed out waiting for ZAP to shutdown.')
            time.sleep(2)

        self.logger.debug('ZAP shutdown successfully.')