def shutdown(self):
        
        MAX_WAIT_SECONDS_BEFORE_SHUTDOWN = 3

        logging.info('Initiating shutdown...')
        self.monitor.stop()
        self.bookmarker.stop()
     
        logging.info('Will shutdown ComicStreamer in maximum %s seconds ...', MAX_WAIT_SECONDS_BEFORE_SHUTDOWN)
        io_loop = tornado.ioloop.IOLoop.instance()
     
        deadline = time.time() + MAX_WAIT_SECONDS_BEFORE_SHUTDOWN
     
        def stop_loop():
            now = time.time()
            if now < deadline and (io_loop._callbacks or io_loop._timeouts):
                io_loop.add_timeout(now + 1, stop_loop)
            else:
                io_loop.stop()
                logging.info('Shutdown complete.')
        stop_loop()
dataset/ETHPy150Open beville/ComicStreamer/comicstreamerlib/server.py/APIServer.shutdown/original