Code here:
def getColor():
return ImageGrab.grab().getpixel(position) #was mouse.position
def crash_detect():
global running, crashed
if isOnL(getColor()):
printColor("(" + str(datetime.now().strftime("%H:%M")) + ")" + " Condition1", Fore.BLUE)
crashed = True
running = False
def finish_detect():
global running
if isInM(getColor()):
printColor("(" + str(datetime.now().strftime("%H:%M")) + ")" + " Condition2", Fore.YELLOW)
running = False
killProcess() #simply kills a process using os.system(taskkill)
def handleExceptions():
crash_detect()
finish_detect()
while True:
while running:
crashed = False
if mouse.position != position:
mouse.position = position
mouse.press(Button.right)
time.sleep(random.uniform(p_duration.__getitem__(0), p_duration.__getitem__(1)))
keyboard.press("h")
time.sleep(random.uniform(w_duration.__getitem__(0), w_duration.__getitem__(1)))
keyboard.release("h")
mouse.release(Button.right)
handleExceptions()
if autoresume and crashed:
crash_recovery()
isOnL and isInM are just functions that compare the color to a set of known colors.
This is part of a script that causes intermittent CPU usage spikes on my laptop; the spikes seem to happen relatively periodically, leading me to think it's because of ImageGrab's getPixel() function. Am I on the right track thinking this, or should I look for the root cause in another place?