From: A. Jesse Jiryu Davis Date: Fri, 27 Mar 2015 10:17:31 +0000 (-0400) Subject: Document locks.Event. X-Git-Tag: v4.2.0b1~50^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ecc0312c57ffe948c8341a2158e0d3a419822bb;p=thirdparty%2Ftornado.git Document locks.Event. --- diff --git a/docs/locks.rst b/docs/locks.rst index 41c1e2bde..c0350dac7 100644 --- a/docs/locks.rst +++ b/docs/locks.rst @@ -72,3 +72,48 @@ multithreaded app.)* The method raises `tornado.gen.TimeoutError` if there's no notification before the deadline. + + Event + ----- + .. autoclass:: Event + :members: + + A coroutine can wait for an event to be set. Once it is set, the coroutine + does not block on `wait` until the the event is unset again: + + .. testcode:: + + from tornado import ioloop, gen, locks + + + io_loop = ioloop.IOLoop.current() + event = locks.Event() + + + @gen.coroutine + def waiter(): + print("Waiting for event") + yield event.wait() + print("Not waiting this time") + yield event.wait() + print("Done") + + + @gen.coroutine + def setter(): + print("About to set the event") + event.set() + + + @gen.coroutine + def runner(): + yield [waiter(), setter()] + + io_loop.run_sync(runner) + + .. testoutput:: + + Waiting for event + About to set the event + Not waiting this time + Done