classification
Title: Add __bool__ to threading.Event and multiprocessing.Event
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, fberger, flub
Priority: normal Keywords: patch

Created on 2009-05-11 21:24 by flub, last changed 2012-01-10 13:49 by fberger. This issue is now closed.

Files
File name Uploaded Description Edit
event.diff flub, 2009-05-11 21:24 Add .__bool__() to threading.Event and multiprocessing.Event
Messages (3)
msg87587 - (view) Author: Floris Bruynooghe (flub) Date: 2009-05-11 21:24
I think it would allow for more pythonic code if the threading.Event and
multiprocessing.Event classes had the __bool__ special attribute.  This
would allow doing "if e: ..." instead of "if e.is_set(): ...".

This could be backported to 2.x really easily by just replacing __bool__
to __nonzero__.

See also the thread starting here:
http://mail.python.org/pipermail/python-ideas/2009-May/004617.html
msg87825 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-05-15 18:13
I'm closing because a lack of positive feedback on the list.
msg151015 - (view) Author: Florian Berger (fberger) Date: 2012-01-10 13:49
Voting for re-opening.

I am currently porting a non-threaded function for use within a threaded application. If threading.Event had __bool__, it would be a drop-in replacement for simple True/False flags that can not be used in multithreaded code.

To me, it is actually surprising that I can not do tests like "if event: ...". IMHO, "if event.is_set(): ..." is unnecessarily complicated, especially with the documentation speaking of a true/false flag all the time.

I will subclass threading.Event now and add __bool__, but I don't feel this is a nice solution.
History
Date User Action Args
2012-01-10 13:49:56fbergersetnosy: + fberger
messages: + msg151015
2010-04-21 16:27:51r.david.murraylinkissue8486 superseder
2009-05-15 18:13:09benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg87825

resolution: rejected
2009-05-11 21:24:18flubcreate