Sikuli uses 100% cpu with wait(image) and observe()

Created by RaiMan
Keywords:
Last updated by:
RaiMan

This is based on Sikuli X 1.0rc3.

In the standard during search operations Sikuli is searching for the visual object continuously. This leads to 100% cpu, since this process is just looping continuously through byte arrays.

This is ok, for find operations, since you expect them to be finished as fast as possible.

If this is a problem for you during a longer wait or observe, feel free to reduce the scan rate to once per second or even less often. This reduces the cpu usage. E.g. searching once every 2 seconds might be acceptable, if you expect something to appear within the next 60 seconds.

look: http://sikuli.org/docx/globals.html#Settings.WaitScanRate

--- the test script:

setROI = selectRegion()
Settings.ObserveScanRate = 1
SCREEN.isFound = False

def handler(e):
    print "in handler"
    e.region.isFound = True
    e.region.stopObserver()

onAppear("logo.png", handler)
observe(FOREVER, True) # runs in background
while not SCREEN.isFound:
    print "waiting"
    wait(5)
print "finished"

"logo.png" was the Sikuli logo in a browser window, that I could hide and reveal by scrolling.

*** Caution:
Currently (rc3) the IDE "remembers" the Settings.ObserveScanRate (not reset to default on rerun). So if you are doing some evaluations in the IDE and want to reset Settings.ObserveScanRate, set it to a high value (e.g. 100). Just commenting out will not do the job. (see bug 857194).

*** BTW:
I never had any problems with this behavior of Sikuli, neither on Mac nor on Windows - at least with the foreground apps and their responsiveness.