These lines at the end of twitch.py jumped out at me.
while True:
asyncio.sleep(0)
This appears to be a busy wait. It will consume CPU unnecessarily.
If you are waiting for a thread, you could use thread.join(). If you are waiting for asyncio co-routines, you can await or gather them.
In this case, there seems to be a mix of both. I suspect the entire extra thread is unnecessary, and you can directly await twitchbot.run(), but I will leave that for you to investigate.
Even replacing the asyncio.sleep(0) with asyncio.sleep(1) would reduce the CPU usage to a negligible amount.
These lines at the end of
twitch.py
jumped out at me.This appears to be a busy wait. It will consume CPU unnecessarily.
If you are waiting for a thread, you could use
thread.join()
. If you are waiting for asyncio co-routines, you canawait
orgather
them.In this case, there seems to be a mix of both. I suspect the entire extra thread is unnecessary, and you can directly await
twitchbot.run()
, but I will leave that for you to investigate.Even replacing the
asyncio.sleep(0)
withasyncio.sleep(1)
would reduce the CPU usage to a negligible amount.