]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
More concise locks examples.
authorA. Jesse Jiryu Davis <jesse@mongodb.com>
Fri, 27 Mar 2015 10:20:40 +0000 (06:20 -0400)
committerA. Jesse Jiryu Davis <jesse@mongodb.com>
Fri, 27 Mar 2015 10:20:40 +0000 (06:20 -0400)
docs/locks.rst

index c0350dac7b62fda2842b0b2bbc0d6ec159d2f276..3dbed192b077ae08db30775da9cc1002171a7d97 100644 (file)
@@ -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()]