X-Git-Url: https://git.ucc.asn.au/?p=progcomp2013.git;a=blobdiff_plain;f=qchess%2Fsrc%2Fthread_util.py;fp=qchess%2Fsrc%2Fthread_util.py;h=2c793300c53ee104047b7983115fd0ff50e7b586;hp=0000000000000000000000000000000000000000;hb=444244d5c7698bb7861cdb7c0ec6bfb0e8cebfb7;hpb=707e794d26062516eb4188d1cd2902929613c46b diff --git a/qchess/src/thread_util.py b/qchess/src/thread_util.py new file mode 100644 index 0000000..2c79330 --- /dev/null +++ b/qchess/src/thread_util.py @@ -0,0 +1,15 @@ +import threading + +# A thread that can be stopped! +# Except it can only be stopped if it checks self.stopped() periodically +# So it can sort of be stopped +class StoppableThread(threading.Thread): + def __init__(self): + threading.Thread.__init__(self) + self._stop = threading.Event() + + def stop(self): + self._stop.set() + + def stopped(self): + return self._stop.isSet()