I've found that most of the time when I use gevent.event.Event
, my code looks something like this:
old_event = self.some_event
self.some_event = Event()
old_event.set()
With the listeners looking something like:
while 1:
self.some_event.wait()
开发者_StackOverflow中文版 … do stuff …
Is this the “right way to do it”? Or is there a better way to notify multiple listeners of a recurring event?
Well, you can also clear()
the event.
event.set()
event.clear()
This will notify the listeners that are currently waiting for the event, but the listeners that are started to wait() later will be blocked until the next call to set()
.
精彩评论