← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #660366]: How to continously run a piece of code while simultaneously checking for a condition?

 

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

    Status: Answered => Open

Martin Roth is still having a problem:
Thanks for your reply and the link. I didn't know about 'break'.
Certainly it will be handy in the future, as well as the rest of the
FAQ.  :) However, this does not entirely answer the question. The
problem is that I want the functions to continue running, without having
to stop and wait for the image explicitly (using 'exists'). I mean, to
eliminate all such pauses. If I put multiple copies of the condition
check, between the defined functions, it will have to wait before
executing the next function.

while True; # starts endless loop
    danceLeft()
    if someRegion.exists(someImg, 1): # check terminating condition, losing 1 seconds
        print("Stopped dancing; the image has appeared!")
        break
    danceRight()
    if someRegion.exists(someImg, 1): # check terminating condition, losing another 1 second
        print("Stopped dancing; the image has appeared!")
        break
    danceAcrossTheHallway()
    if someRegion.exists(someImg, 1): # check terminating condition, losing yet another 1 second
        print("Stopped dancing; the image has appeared!")
        break

Perhaps this could work, if I make the condition check is short enough, but it doesn't feel optimal.
I was hoping there would be a way of continuously watching for an image in a region, while running / looping some functions in parallel, and stopping / breaking the loop while the condition is met.

Otherwise the condition check will have to be inserted everywhere, or
atleast every now and then, in the loop, and the ride won't be smooth.

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.