Andriy Mysyk added the comment: Example added to threading.rst
For example, the following code demonstrates a controlled thread termination using an event object. The event is used to request the termination of several threads. import threading import time stopevent = threading.Event() class TestThread(threading.Thread): def run(self): """ main control loop """ print ("Thread ", self.ident, " starts") count = 0 while not stopevent.is_set(): count += 1 stopevent.wait(1.0) print ("loop ", count, "in thread ", self.ident) print ("Thread ", self.ident, " ends") for i in range (2): testthread = TestThread() testthread.start() time.sleep (3) stopevent.set() ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue17808> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com