1

I have an Observer running in background forever, that is looking for a specific pattern, and will call the handler rdp_handler when triggererd:

onAppear("1615387075076.png", rdp_handler)
observeInBackground()

The handler is supposed to wait FOREVER or to wait for the pattern to vanish:

print "rdp_handler called"
waitVanish("1615387075076.png", FOREVER)
print "rdp_handler finished"

Basically what I'm trying to do is pause the execution of the script until the pattern vanish, obviously this doesn't work because the handler is executed in a Thread, so the Thread is paused but my main programm keep running.

I tried to import psutil to suspend the java process, but I get the following traceback (after adding the path to the site-package directory):

[error] script [ OrderCreate ] stopped with error in line 11
[error] NotImplementedError ( platform java13.0.2 is not supported )
[error] --- Traceback --- error source first
line: module ( function ) statement 
143: __init__ (  <module> )     raise NotImplementedError('platform %s is not supported' % sys.platform)
11: main (  <module> )     import psutil
[error] --- Traceback --- end --------------

After some research I found out that I can only import java and pur python lib, psutil has some C code in it...

Here come my question: do you have a clue on how to proceed to pause the main programm until the handler is done doing his stuff ?

Ben
  • 25
  • 6

3 Answers3

0

Try:

import time
while(not waitVanish("1615387075076.png", FOREVER)):
    time.sleep(1)

This should check every second for vanishing.

Curtis
  • 548
  • 3
  • 13
  • Thanks for your answer, however I have found an alternative that work fine and is "cleaner" (but use more performance), I will post it when I have time – Ben Mar 19 '21 at 10:49
0

Soooo after trying some funky stuff, I managed to get something working, the only problem is: I have to add some if statement at crutial part of my script:

at the start I define my event and start my observer:

my_event = onAppear("1615387075076.png")
observeInBackground()

I then created a function:

def rdp_handler(my_event):
    if exists("1615387075076.png"):
        print("RDP disconnected")
        waitVanish("1615387075076.png", FOREVER)
        print("RDP reconnected")
        setActive(my_event)

Now each time I interact with the interface, I do this:

if hasEvents():
    SageUtils.rdp_handler(my_event)

hasEvents() return True if my pattern appeared at one time of my program, if it's True, I call rdp_handler(my_event) that will check if the pattern is still on screen, if it is, then it will wait for it to vanish, and reactivate my event used in my observer.

It is ugly but hey, it work.

I'm still opened to better/cleaner solution, but yeah so far I'm happy.

Ben
  • 25
  • 6
0

RaiMan from SikuliX:

What you want is currently not available as a feature of SikuliX.

This is the best answer you can get here: https://stackoverflow.com/a/16899837/1918124

... but there is indeed a hidden feature, that at least allows to block the script, the next time it tries to issue a mouse action. I will try with your case the next days, wether this principally works.

If you are interested, add an issue here, so you can get a follow up.

RaiMan
  • 1,088
  • 8
  • 13
  • Hey RaiMan, thanks for your answer, I have found a way to do what I want: I start a second sikuli script running the Observer, when it detects a specified pattern, it call PSTools pssuspend.exe with the PID of my main Sikuli script, and once the pattern vanish, it resume it the same way. – Ben Mar 19 '21 at 08:21
  • Thanks for feedback. Appreciate to see your approach. – RaiMan Mar 19 '21 at 14:37