so I'm running a very rudimentary webcam surveillance program with PyGame, that just takes a picture from the webcam, stamps the time and saves it in an endless loop. (and does some simple date checking and sometimes writes to a log file)

I have put time.sleep(1) at the end, because it's sufficient for my cause and of course I wanted to keep CPU usage low.

But whenever I check the CPU usage with top, htop or ps -o %cpu the CPU usage of python is alternating between 35% and 55%. I feel like that's way too much for a program that only runs every second.

I also tried pygame.time.delay(1) but that's not really better.

Am I missing something or is PyGame just not the best choice for my task?

  • if, for example you change time.sleep(1) to time.sleep(10) how does that effect the cpu usage – Jaromanda X Feb 20 at 23:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.