HS-Tools / Wall_Lii

Does leaderboard scraping and then does stuff with that data
18 stars 7 forks source link

Investigate Busy Wait. #89

Closed Julian-O closed 3 years ago

Julian-O commented 3 years ago

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.

JimLiu0 commented 3 years ago

Thanks, it seems you are correct. #90 has resolved this.