Relatively simple Python script using 100% CPU
I will not provide the code because it is too long. Python script involves executing a large number of commands executed in a while loop.
Basic structure
while True:
The meat goes here
with the odd if:
and stuff
Now that I'm done, I notice that it is using 100% CPU on startup, no exceptions. I'm a beginner and don't know what this refers to. I thought that maybe because the script is running indefinitely (until I exit it manually), it might just clothe the CPU if it repeats the loop a few times per second. I added time.sleep (1) at the bottom of the time to make sure this is a problem with no improvement.
Does anyone have any idea? It's a rather long sequence of events, but they rely heavily on the if statement, which doesn't run as often. 100% CPU usage happens before this if statement even fires, so I'm really at a loss.
Edit: forgot to include that it works in unix environment (Debian)
source to share
If there is anything that interferes with the CPU being used (such as waiting for disk I / O or network I / O, or suspending the execution of a hibernate), the CPU utilization will always be around 100% while the program is running.
You may need to add time.sleep (numberOfSeconds) to your loop if you don't want it to use 100% CPU all the time if it only checks a certain state over and over again.
source to share