← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #225268]: Sikuli MMC, workaround doesn´t work

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
Might be, that restarting the observer in the handlers leads to holding
memory and blocking some garbage collection.

When using a foreground observer (which is the default), you should do
it this way:

observingShouldStop = False

def StopSikuliNow(event):
 global observingShouldStop
 event.region.stopObserver()
 popup(u"Die Sikuli Bildschirmüberwachung wurde beendet")
 observingShouldStop = True

def FM_Fehler_Hung(event):
 event.region.stopObserver()
 click(event.match)
 doubleClick(wait("timer.png", 10))
 
def FM_Fehler_InUse(event):
 event.region.stopObserver()
 click(event.match)

def FM_Fehler_AccessDenied(event):
 event.region.stopObserver()
 click(Pattern(event.match)

Settings.ObserveScanRate = 0.0333 # alle 30 Sekunden
onAppear("shutdown.png",StopSikuliNow)

imgFMClose = Pattern("fmclose.png").targetOffset(-76,50)
onAppear(imgFMClose,FM_Fehler_Hung)

imgFMInUse = Pattern("meldungsende.png").similar(0.40).targetOffset(137,-4)
onAppear(imgFMInUse, FM_Fehler_InUse)

imgFMAccessDenied = Pattern("1FileMakerPr.png").similar(0.60).targetOffset(117,43)
onAppear(imgFMAccessDenied, FM_Fehler_AccessDenied)

while True:
 observe(FOREVER)
 if observingShouldStop: break
 wait(10)

Just look, wether the memory leak problem has vanished now

More tips:
- the in-handler-process should be as short as possible (as a general guideline, since it is blocking anything else - might not be of importance in your case), so if you already know where to click (onAppear event), you do not need to search again the same image  in the handler, but use event.match instead (see docs)

- you seem to have captured the same images more than once: this should
be avoided for the sake of robustness and clarity.

- images should match with a similarity beyond 0.8 (better 0.9), to
avoid false positives. capture as little background as possible and
concentrate on the key distinguishing visual aspects. If this is not
possible or not wanted, restrict the search region to the smallest
possible area, where you expect the image to appear (there are many
Region functions, that help to define other regions based on existing
regions and matches).

As a convention in Python/Jython, names of variables and
functions/methods should start with a lowercase letter. Only class names
and optionally module names should start with uppercase letters.

One more thing:
a version without observe having much less noise and is doing the same:

while True:
    if exists("shutdown.png", 0): break

    if exists(Pattern("fmclose.png").targetOffset(-76,50), 0):
        click(getLastMatch())
        doubleClick(wait("timer.png", 10))

    elif exists(Pattern("meldungsende.png").similar(0.40).targetOffset(137,-4), 0):
        click(getLastMatch())

    elif exists(Pattern("1FileMakerPr.png").similar(0.60).targetOffset(117,43), 0):
        click(getLastMatch())

    wait(30)
    
popup(u"Die Sikuli Bildschirmüberwachung wurde beendet")

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