Issue 17808: No code example for Event object in threading module (original) (raw)

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:44 admin set github: 62008
2020-11-17 15🔞08 iritkatriel set status: open -> closedresolution: rejectedstage: resolved
2013-04-22 00:21:49 amysyk set messages: +
2013-04-21 12:41:45 pitrou set nosy: + pitroumessages: +
2013-04-21 03:36:20 amysyk set messages: +
2013-04-21 03:33:02 amysyk set files: + bug17808.patchassignee: docs@pythoncomponents: + Documentationkeywords: + patchnosy: + docs@pythonmessages: +
2013-04-21 02:58:48 amysyk set messages: +
2013-04-21 02:57:33 amysyk create