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.

classification
Title: No code example for Event object in threading module
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.4
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: docs@python Nosy List: amysyk, docs@python, pitrou
Priority: normal Keywords: patch

Created on 2013-04-21 02:57 by amysyk, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bug17808.patch amysyk, 2013-04-21 03:33 patch to add a code example review
Messages (6)
msg187486 - (view) Author: Andriy Mysyk (amysyk) * Date: 2013-04-21 02:57
Documentation for Event objects in threading module could be more clear with a code example.

http://docs.python.org/3.4/library/threading.html#event-objects
msg187487 - (view) Author: Andriy Mysyk (amysyk) * Date: 2013-04-21 02:58
I will create a code example by the end of Sunday, April 21.
msg187488 - (view) Author: Andriy Mysyk (amysyk) * Date: 2013-04-21 03:33
See the patch with a code example attached.
msg187489 - (view) Author: Andriy Mysyk (amysyk) * Date: 2013-04-21 03:36
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()
msg187501 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-04-21 12:41
An example should generally show something interesting or non-obvious, which isn't the case here. IMHO an Event is simple enough to use that it doesn't need an example; furthermore, the example you are proposing doesn't really showcase anything interesting, functionally :-)
msg187540 - (view) Author: Andriy Mysyk (amysyk) * Date: 2013-04-22 00:21
Thank you for the feedback, Antoine. 

The example shows how to essentially kill threads through an event facilitated request, something that I consider to be useful and non-obvious.

I trust that you and others will make the right decision and will keep your feedback in mind for any future patches.
History
Date User Action Args
2022-04-11 14:57:44adminsetgithub: 62008
2020-11-17 15:18:08iritkatrielsetstatus: open -> closed
resolution: rejected
stage: resolved
2013-04-22 00:21:49amysyksetmessages: + msg187540
2013-04-21 12:41:45pitrousetnosy: + pitrou
messages: + msg187501
2013-04-21 03:36:20amysyksetmessages: + msg187489
2013-04-21 03:33:02amysyksetfiles: + bug17808.patch

assignee: docs@python
components: + Documentation

keywords: + patch
nosy: + docs@python
messages: + msg187488
2013-04-21 02:58:48amysyksetmessages: + msg187487
2013-04-21 02:57:33amysykcreate