oberserveInBackground question

Asked by Ben Dix


I am trying to use the observeInBackground() function to react, if a notification pops up.
I red all the documentation, but looks like I can not find how to use this in subthread while my script is running...

can someone help me how to observeInBackground() if an image appears and how to define any action, that should be followed, while pausing the main thread?

I tried this, found in the another post:

R = Region(103,957,437,64)
def axn(event):


but still don't know how to set an if condition when image is found....

greetings and thx for helping.

Question information

English Edit question
SikuliX Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :

Without any coordination between onAppear handler (your def axn) and the main workflow (observeInBackground in fact runs in a thread and hence the handler also), the reactive actions have all to be done in the handler. Depending on the kind of the actions, they might interfere with the main workflow (mouse and/or keyboard actions).

So in your case, you should start with the implementation of the handler and see wether it does what it should.

If you get interference problems with the main workflow, then you have to do some synchronising.

Easiest: use some global variables, that are set/unset and checked at places of interest. Depending on the state, something waits for a state change to proceed. Be careful about possible deadlocks.

At low level the current implementation guarantees, that one mouse action (click = move, down, up) is completed, before another one can start (relevant in your case). This is usually sufficient to click away a popup in a background handler.

For more options, you have to come back after having made some experiences ;-)

Revision history for this message
RaiMan (raimund-hocke) said :

There is an actual question about observeInBackground:


beginning with comment #5

Can you help with this problem?

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

To post a message you must log in.