开发者

Better pattern for multi-listener notifications with `gevent.event.Event`?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜