def run(self, *args, **kwargs):
    loop = self.loop
    try:
        loop.add_signal_handler(signal.SIGINT, (lambda : loop.stop()))
        loop.add_signal_handler(signal.SIGTERM, (lambda : loop.stop()))
    except NotImplementedError:
        pass
    asyncio.ensure_future(self._bot_runner_task(*args, *kwargs), loop=loop)
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        loop.stop()
        log.info('Received signal to terminate bot and event loop')
    log.info('Shutting down the bot...')
    tasks = {t for t in asyncio.all_tasks(loop=loop) if (not t.done())}
    for task in tasks:
        task.cancel()
    loop.run_until_complete(asyncio.gather(*tasks, return_exceptions=True))
    for task in tasks:
        if (not task.cancelled()):
            log.error('Asynchronous task cancel failed!')
    loop.run_until_complete(loop.shutdown_asyncgens())
    loop.run_until_complete(self._on_shutdown())
    loop.close()
    log.info('Bot is shut down!')
def run(self, *args, **kwargs):
    loop = self.loop
    try:
        loop.add_signal_handler(signal.SIGINT, (lambda : loop.stop()))
        loop.add_signal_handler(signal.SIGTERM, (lambda : loop.stop()))
    except NotImplementedError:
        pass
    asyncio.ensure_future(self._bot_runner_task(*args, *kwargs), loop=loop)
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        loop.stop()
        log.info('Received signal to terminate bot and event loop')
    log.info('Shutting down the bot...')
    tasks = {t for t in asyncio.all_tasks(loop=loop) if (not t.done())}
    for task in tasks:
        task.cancel()
    loop.run_until_complete(asyncio.gather(*tasks, return_exceptions=True))
    for task in tasks:
        if (not task.cancelled()):
            log.error('Asynchronous task cancel failed!')
    loop.run_until_complete(loop.shutdown_asyncgens())
    loop.run_until_complete(self._on_shutdown())
    loop.close()
    log.info('Bot is shut down!')