Sikuli MMC, workaround doesn´t work

Asked by Stefan Pusch

I have the following script:

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

def FM_Fehler_Hung(event):
 event.region.stopObserver()
 click(Pattern("fmclose.png").targetOffset(-76,50))
 wait(10)
 doubleClick("timer.png")
 wait(10)
 observe(FOREVER, background=False)

def FM_Fehler_InUse(event):
 event.region.stopObserver()
 click(Pattern("meldungsende.png").targetOffset(121,0))

 wait(10)
 observe(FOREVER, background=False)

def FM_Fehler_AccessDenied(event):
 event.region.stopObserver()
 click(Pattern("1FileMakerPr.png").similar(0.60).targetOffset(130,43))
 wait(10)
 observe(FOREVER, background=False)

Settings.ObserveScanRate = 0.0333 # alle 30 Sekunden
onAppear("shutdown.png",StopSikuliNow)
onAppear("fmclose.png",FM_Fehler_Hung)
onAppear(Pattern("1FileMakerPr.png").similar(0.60).targetOffset(117,43), FM_Fehler_AccessDenied)
onAppear(Pattern("meldungsende.png").similar(0.40).targetOffset(137,-4), FM_Fehler_InUse)
observe(FOREVER, background=False)

The script runs when started manually with a bat file but produces memory leak errors from time to time. My idea was to stop/start it every 2 hours with the taskplaner.
I used the workaround (https://answers.launchpad.net/sikuli/+question/166785) and started Sikuli-IDE-w.bat and pasted my script path as parameter. (As described) The process (java32.exe) starts up but the script doesn´t do anything. I think it is the "input error" when started from the MMC; Any clues why the workaround doesn´t work? If anyone has a clue why there are memory leaks appearing - go ahaed; Sikuli is really new to me!
System: Win7Pro-64bit
Java 6 Update 38

Question information

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

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

Can you help with this problem?

Provide an answer of your own, or ask Stefan Pusch for more information if necessary.

To post a message you must log in.