Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13951

High CPU usage when idle

$
0
0

I would like to get an answer for this question: Why when no actions are being performed, my python program takes 14% of CPU, but when actions inside the loop are performed (toggle) it is only at 4%? (what I use is os, keyboard, pyautogui, time and Image from PIL)

So the problem is that it takes more CPU when it didn't perform any actions except checking for keyaboard press, than when doing all the presses and image findings.

I tryed searching this answer online, but my search was unsuccessful.

toggle = Falsewhile True:    if keyboard.is_pressed(TOGGLE_KEY):        toggle = not toggle        if toggle:            print('Dialogue Skipping ON.')        else:            print('Dialogue Skipping OFF.')            time.sleep(1)    if toggle:        pyautogui.click(*DIALOGUE_SKIP_POSITION)        pyautogui.press('space')        try:            dialogue = pyautogui.locateOnScreen(                dialogue_image, confidence=CONFIDENCE_THRESHOLD, region=SEARCH_REGION)            if dialogue:                pyautogui.click(dialogue)        except pyautogui.ImageNotFoundException:            pass

Viewing all articles
Browse latest Browse all 13951

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>