[issue29449] clear() should return prior state in threading.Event

Jyotirmoy Bhattacharya report at bugs.python.org
Mon Feb 6 03:56:19 EST 2017


Jyotirmoy Bhattacharya added the comment:

> > A return value from clear will indicate to a thread if it
> > won the race to clear the event.
>
> Why would we care who won the race to clear? I would think that the
> important thing is that the event is cleared, not who did it.
>

Here's the scenario that prompted my report: the Event is set to indicate
that certain 'work' has accumulated and one among a pool of workers uses
clear() to claim the work accumulated till that point. If clear() returned
a value, we could easily ensure that only one among the workers woken up
actually does the work.

Of course, in this case it would be more efficient to wake up just one
worker using a Condition object and notify() but then one has to write the
logic to maintain the state of the event. An Event whose clear() returned a
value would allow for a quick and dirty solution.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29449>
_______________________________________


More information about the Python-bugs-list mailing list