sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #00300
Re: [Question #140946]: How to multi thread
Question #140946 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/140946
RaiMan posted a new comment:
since reg is not defined in the local context and supposing it is not a
global variable, this should raise a Name exception and stop the thread.
We ;-) should have a look, how to catch this and where (Python docs).
A thread is ended, when it gets to an explicit or implicit return. If It
is ended if the main dies, depends on the system around. On my Mac, it
seems, that the sub is ended, when the main ends (but not really sure).
So if you use the your forced termination, you have to live with it.
You might try to use some "I'm alive" status with the locking feature.
Here is something to play with:
import thread
def sub(alive):
while True:
x = alive.locked()
print "sub running:", x
if not x:
print "sub stopped:", x; return
wait(3)
print "main started"
alive = thread.allocate_lock()
if alive.acquire(): print "main locked:", alive.locked()
else: exit(1)
thread.start_new_thread(sub, (alive, ))
wait(10)
alive.release() # sub stops after this
maybe the lock is set to false (that's what we need), when main
vanishes. give it a try.
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.