http://eventlet.net/doc/modules/event.html
功能:用来在协程之间通信
class eventlet.event.
Event
An abstraction where an arbitrary number of coroutines(任意数量的协同程序) can wait for one event from another.
Events are similar to a Queue that can only hold one item, but differ in two important ways:
- calling
send()
never unschedules the current greenthread send()
can only be called once; create a new event to send again.
They are good for communicating results between coroutines, and are the basis for how GreenThread.wait()
is implemented(他们有助于在协同程序之间传达结果,并且是实现GreenThread.wait()的基础).
-
Return true if the
wait()
call will return immediately. Used to avoid waiting for things that might take a while to time out. For example, you can put a bunch of events into a list, and then visit them all repeatedly, callingready()
until one returnsTrue
, and then you canwait()
on that one. -
例如,您可以将一堆事件放入列表中,然后重复访问它们,调用ready()直到返回True,然后可以wait()在那一个。
ready
(
)
-
Makes arrangements for the waiters to be woken with the result and then returns immediately to the parent.
It is an error to call
send()
multiple times on the same event.Use
reset()
betweensend()
s to reuse an event object.
send
(
result=None,
exc=None
)
-
Same as
send()
, but sends an exception to waiters.The arguments to send_exception are the same as the arguments to
raise
. If a single exception object(异常对象) is passed in, it will be re-raised whenwait()
is called, generating a new stacktrace. send_exception的参数与引用的参数相同。 如果传入一个异常对象,调用wait()时会重新生成一个异常对象,生成一个新的堆栈跟踪If it’s important to preserve(保护) the entire original stack trace, you must pass in the entire
sys.exc_info()
tuple.Note that doing so stores a traceback object directly on the Event object, which may cause reference cycles. See the
sys.exc_info()
documentation.
send_exception
(*args)