Script using too much resources

Asked by Joe Hammer

Hi there,

I'm trying to write a script which waits for a certain text to show up in the Chrome browser and then closes the browser.

I wrote one that seems to work, but it uses up so much resources when I run it as an executable (apx. 50% of the CPU time).

This is the script:

Settings.ObserveScanRate = 0.0001

while not exists("Closethiswin.png",10):
   sleep (1)

click("1335800413150.png")

Does anyone know how I can rewrite it so as not to use up so much resources?

Kind regards

Buggo

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Joe Hammer
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

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 ;-)

Revision history for this message
Joe Hammer (workmail123456) said :
#2

Hi there RaiMan,

What I did was creating a list of simple if exists "x.png" - click "close.png" statements and made an executable file of it that I run every 5 minutes or so. It was the easiest way I could find to solve this problem.

I appreciate your advice and I might try to learn more about Sikuli in the feature, I am interested in this GUI programming thing.

Kind regards

Buggo