Message187489
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() |
|
Date |
User |
Action |
Args |
2013-04-21 03:36:20 | amysyk | set | recipients:
+ amysyk, docs@python |
2013-04-21 03:36:20 | amysyk | set | messageid: <1366515380.5.0.899163704229.issue17808@psf.upfronthosting.co.za> |
2013-04-21 03:36:20 | amysyk | link | issue17808 messages |
2013-04-21 03:36:20 | amysyk | create | |
|