← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #195431]: Script using too much resources

 

Question #195431 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/195431

    Status: Open => Answered

RaiMan proposed the following answer:
Uuups that is "functional overkill" ;-)

Reducing the scan rate for normal find operations:
Settings.WaitScanRate = 1 # once a second
Settings.WaitScanRate = 0.5 # once every 2 seconds
Settings.WaitScanRate = 1/10 # once every 10 seconds
....

Settings.ObserveScanRate is only for the observe() feature.

while not exists("Closethiswin.png",10):
   sleep (1)
This will wait about 10 seconds for the image and the sleep 1 second and start again waiting for the image.
Since you used the wrong scan rate, it tries to search 3 times per second.
But since in your case the whole screen is searched, your script is constantly searching (each full screen search takes about one second with cpu intensive number crunching).

so this might help:

while not exists("Closethiswin.png", 0):
      sleep(3)

This will search once ( exists(image, 0) ) every 3 seconds.

To further reduce the cpu consumption for searching you might restrict
the search to a smaller region where you expect the image to appear and
say:

reg = some_evaluated_region
while not reg.exists("Closethiswin.png", 0):  wait(3)

sleep() is deprecated, use wait() instead.

reading through faq 1607 might give you some more ideas about saving
resources in Sikuli scripts.

BTW: when I run it as an executable 
It is no longer necessary, to export a script as executable to run it from command line. Just use the my_script.sikuli for these cases.
Sikuli's "executables" are only zipped versions of the .sikuli folders.
This might make sense, if you want to give your script to someone else by mail or downloadable from the net (and he might not see your script, if he does not have the idea, to simply unzip it ;-)

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.