From: A. Jesse Jiryu Davis Date: Fri, 27 Mar 2015 10:20:40 +0000 (-0400) Subject: More concise locks examples. X-Git-Tag: v4.2.0b1~50^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83d07d8012592aed1eee1b7688429c777804b2a4;p=thirdparty%2Ftornado.git More concise locks examples. --- diff --git a/docs/locks.rst b/docs/locks.rst index c0350dac7..3dbed192b 100644 --- a/docs/locks.rst +++ b/docs/locks.rst @@ -11,6 +11,11 @@ place of those from the standard library--they are meant to coordinate Tornado coroutines in a single-threaded app, not to protect shared objects in a multithreaded app.)* +.. testsetup:: + + from tornado import ioloop, gen, locks + io_loop = ioloop.IOLoop.current() + .. automodule:: tornado.locks Condition @@ -22,27 +27,20 @@ multithreaded app.)* .. testcode:: - from tornado import ioloop, gen, locks - - - io_loop = ioloop.IOLoop.current() condition = locks.Condition() - @gen.coroutine def waiter(): print("I'll wait right here") yield condition.wait() # Yield a Future. print("I'm done waiting") - @gen.coroutine def notifier(): print("About to notify") condition.notify() print("Done notifying") - @gen.coroutine def runner(): # Yield two Futures; wait for waiter() and notifier() to finish. @@ -83,13 +81,8 @@ multithreaded app.)* .. testcode:: - from tornado import ioloop, gen, locks - - - io_loop = ioloop.IOLoop.current() event = locks.Event() - @gen.coroutine def waiter(): print("Waiting for event") @@ -98,13 +91,11 @@ multithreaded app.)* yield event.wait() print("Done") - @gen.coroutine def setter(): print("About to set the event") event.set() - @gen.coroutine def runner(): yield [waiter(), setter()]