diff -r 2add6c86f38e Doc/library/concurrency.rst --- a/Doc/library/concurrency.rst Wed Apr 17 04:36:45 2013 +0300 +++ b/Doc/library/concurrency.rst Sat Apr 20 20:29:54 2013 -0700 @@ -8,7 +8,7 @@ execution of code. The appropriate choice of tool will depend on the task to be executed (CPU bound vs IO bound) and preferred style of development (event driven cooperative multitasking vs preemptive -multitasking) Here's an overview: +multitasking). Here's an overview: .. toctree:: diff -r 2add6c86f38e Doc/library/threading.rst --- a/Doc/library/threading.rst Wed Apr 17 04:36:45 2013 +0300 +++ b/Doc/library/threading.rst Sat Apr 20 20:29:54 2013 -0700 @@ -814,6 +814,33 @@ .. versionchanged:: 3.1 Previously, the method always returned ``None``. + +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") + + #create two looping threads and terminate them using an event + for i in range (2): + testthread = TestThread() + testthread.start() + time.sleep (3) + stopevent.set() .. _timer-objects: