Fix bot event loop

master
Nikola Forró 6 years ago
parent 8270f8e183
commit 15a659cfd1

@ -37,22 +37,30 @@ def main():
commands = Commands(config, commands_logger) commands = Commands(config, commands_logger)
discord_client = DiscordClient(config, discord_logger, commands)
async def run_twitch_client(): async def run_twitch_client():
twitch_client = TwitchClient(config, twitch_logger, commands) twitch_client = TwitchClient(config, twitch_logger, commands)
twitch_client.connect_() twitch_client.connect_()
while True: while True:
twitch_client.process_data() try:
await asyncio.sleep(TIMEOUT) twitch_client.process_data()
await asyncio.sleep(TIMEOUT)
asyncio.ensure_future(run_twitch_client()) except Exception as e:
twitch_logger.info('Exception', exc_info=e)
async def run_discord_client():
discord_client = DiscordClient(config, discord_logger, commands)
while True:
try:
await discord_client.start_()
except Exception as e:
discord_logger.info('Exception', exc_info=e)
await discord_client.logout()
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
try: try:
loop.run_until_complete(discord_client.start_()) asyncio.ensure_future(run_twitch_client())
except: asyncio.ensure_future(run_discord_client())
loop.run_until_complete(discord_client.logout()) loop.run_forever()
finally: finally:
loop.close() loop.close()

Loading…
Cancel
Save