Python Forum
Very High CPU Usage [Networking, Threads]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Very High CPU Usage [Networking, Threads]
#5
I don't like the idea the while True loop with a if queue.Empty() either. Instead, you can do
try:
    value = self.input_queue.get(timeout=0.1)
except queue.Empty:
    continue
else:
    ...
The correct way to wait in threads is not to use time.sleep() statements. Instead you can wait with a timeout on queues or locks or condition objects, or perhaps use selectors that also wait with timeouts.
iMuny likes this post
Reply


Messages In This Thread
RE: Very High CPU Usage [Networking, Threads] - by Gribouillis - Jan-10-2020, 09:55 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020