From d750105a77caf9e0ee60ea97445409c3dae15a1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Tue, 10 Mar 2020 21:07:52 +0100 Subject: [PATCH] Await do stuff in irc bot (#486) --- src/ircbot/irc3module.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/ircbot/irc3module.py b/src/ircbot/irc3module.py index 2f2a6e3e..8672337c 100644 --- a/src/ircbot/irc3module.py +++ b/src/ircbot/irc3module.py @@ -1,6 +1,7 @@ import logging import re import time +import asyncio import irc3 from asgiref.sync import sync_to_async @@ -44,9 +45,8 @@ class Plugin(object): "Calling self.bot.do_stuff() in %s seconds.." % settings.IRCBOT_CHECK_MESSAGE_INTERVAL_SECONDS ) - self.bot.loop.call_later( - settings.IRCBOT_CHECK_MESSAGE_INTERVAL_SECONDS, self.bot.do_stuff - ) + await asyncio.sleep(settings.IRCBOT_CHECK_MESSAGE_INTERVAL_SECONDS) + await self.bot.do_stuff() def connection_lost(self, **kwargs): """triggered when connection is lost""" @@ -123,9 +123,8 @@ class Plugin(object): await sync_to_async(self.bot.get_outgoing_messages)() # schedule a call of this function again in N seconds - self.bot.loop.call_later( - settings.IRCBOT_CHECK_MESSAGE_INTERVAL_SECONDS, self.bot.do_stuff - ) + await asyncio.sleep(settings.IRCBOT_CHECK_MESSAGE_INTERVAL_SECONDS) + await self.bot.do_stuff() @irc3.extend def get_outgoing_messages(self):