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
.. 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.
.. 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("Done")
-
@gen.coroutine
def setter():
print("About to set the event")
event.set()
-
@gen.coroutine
def runner():
yield [waiter(), setter()]