← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #225919]: multi-thread performance hit

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
Generally, you can expect your script to get faster with multithreading
on a machine having more than one processor.

But Sikuli generally as such is not thread safe with respect to the generated objects like Screen, Region, Match, ... and updating their attributes.
So a thread should always have its own distinct set of objects (which is not trivial, when using the Python level: the "invisible" constant object SCREEN is used for all unqualified Region methods: click() is seen as SCREEN.click()).
So always use new (Region) objects in your threads (except in cases, where you exactly know, what you are doing).

The real problem with threading is the concurrent usage of mouse and
keyboard: this is definitely not coordinated by Sikuli among threads.

So when using e.g. the mouse in a thread, this might interfere with its
usage in the main or other threads.

The only way, to manage that is to build a queue of thread mouse
actions, that are processed before the next mouse action in main, if the
queue is not empty. the threads have to wait until their next mouse
action is processed and removed from the queue.

The easiest way, to manage your situation with popups is to use
def popup1(e):
    # handle event e.g.
    e.region.click(e.match)
reg1.onAppear("popup1.png", popup1)
reg1.observe(FOREVER, background=True)

which will dispatch the observation and its handling to a thread.

But be aware: all the above aspects are still valid.

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