How to pause main script while observe handler is working --- not possible in 1.1.x

Asked by Armel

Hy,

I've just try use observe function. And I've a very very big problem.

This is my code :

def test(event):
     <here is my code>
     <....>
     <....>
     event.repeat()

onAppear(img1,test)
observeInBackground(FOREVER)

# Main script

doubleClick(img2)
...
...
...
...

So, when img1 appears, the function "test" is running .

But the main script continues !!!

How can I stop the main script until the end of the handler ???

thanks in advance...

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

Yep, that is not possible using observeInBackground()
... and will not be a feature in version 1.1.x (on the list for version 2: some global locking)

With the latest SikuliX (nightly 1.1.1) it is only guaranteed, that mouse actions on the same region object are done completely one after the other (e.g. move and click). In versions before even mouse actions in main and handler could be mixed up.

One possible way is to use a global variable to communicate between main and handler, set it in the handler at entry, unset it in the handler at exit and then in main check the state before going into critical sections.

Another option always is, to redesign the workflow to get rid of observeInBackground() (e.g. use observe/exists at respective places in the workflow)

Revision history for this message
edlothiad (edlothiad) said :
#2

Could you provide any advice for a work around? You've mentioned using a global variable, but if I'm expecting to be able to preform several finds in that period and an unexpected popup appears, would there be a "clever" or efficient way of protecting the script?

Would using try statements with a check in the except be practical (they'd have to wrap almost everything if it was a random popup, no?) or testing for the global variable before clicks?

Can you help with this problem?

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

To post a message you must log in.