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()
    … 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().

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top