This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author amysyk
Recipients amysyk, docs@python
Date 2013-04-21.03:36:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1366515380.5.0.899163704229.issue17808@psf.upfronthosting.co.za>
In-reply-to
Content
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()
History
Date User Action Args
2013-04-21 03:36:20amysyksetrecipients: + amysyk, docs@python
2013-04-21 03:36:20amysyksetmessageid: <1366515380.5.0.899163704229.issue17808@psf.upfronthosting.co.za>
2013-04-21 03:36:20amysyklinkissue17808 messages
2013-04-21 03:36:20amysykcreate