Prevent multiple stop_async calls

This commit is contained in:
Sven Heidemann 2022-10-02 13:25:29 +02:00
parent fa50123d3b
commit d5a1c15db3

View File

@ -34,6 +34,8 @@ class Application(DiscordBotApplicationABC):
self._translation: TranslationServiceABC = services.get_service(TranslationServiceABC) self._translation: TranslationServiceABC = services.get_service(TranslationServiceABC)
self._translate: TranslatePipe = services.get_service(TranslatePipe) self._translate: TranslatePipe = services.get_service(TranslatePipe)
self._is_stopping = False
async def configure(self): async def configure(self):
self._translation.load_by_settings(self._configuration.get_configuration(TranslationSettings)) self._translation.load_by_settings(self._configuration.get_configuration(TranslationSettings))
@ -47,6 +49,10 @@ class Application(DiscordBotApplicationABC):
self._logger.error(__name__, 'Start failed', e) self._logger.error(__name__, 'Start failed', e)
async def stop_async(self): async def stop_async(self):
if self._is_stopping:
return
self._is_stopping = True
try: try:
self._logger.trace(__name__, f'Try to stop {DiscordBotService.__name__}') self._logger.trace(__name__, f'Try to stop {DiscordBotService.__name__}')
await self._bot.close() await self._bot.close()