I just shipped Toro with a new feature contributed by Alexander Gridnev: a readers-writer lock, or "RWLock". It protects a shared data structure by allowing multiple coroutines to lock it for reads. As soon as a coroutine wants to modify the structure it requests a write-lock and waits for all readers to release their locks. While a writer is waiting, all readers and writers queue. Once the writer releases the lock, readers or the next writer can acquire it.
An RWLock is a common optimization for multithreaded code in other languages, but Python threads specifically have no use for one: the Global Interpreter Lock prevents multiple readers from actually doing parallel computation with the shared data, so in multithreaded Python there's no advantage to an RWLock compared to a plain Lock. Thus there's no RWLock in Python's standard threading module.
For async code, however, I could see the advantage of an RWLock. Async Python allows concurrent I/O operations in a single thread. There might be some shared external data that can be retrieved or modified, say a RESTful resource that doesn't implement the desired locking semantics on its own. With Alexander's new RWLock, coroutines in a Tornado process can now safely share such a resource, ensuring that reader coroutines wait for the lock as little as possible, while writer coroutines can gain exclusive access to the resource when needed.
I recognized the usefulness of this kind of lock so I took the contribution. Besides, asyncio expert Andrew Svetlov made an RWLock for asyncio so I thought Tornado deserved one, too. Toro was a good place for such a class to make its temporary home. RWLock is Toro 1.0's sole new feature.
And now it's the end of the line: Toro is both completed and deprecated. Toro's locks and queues were merged into Tornado 4.2, and further development on those ideas will continue in Tornado itself from now on. Indeed, Ben Darnell has just updated Tornado's locks and queues for Python 3.5's new async
and await
statements. I've recommended to Alexander that he spin off his RWLock for Tornado into a separate package, to stand alone the same as asyncio's RWLock does.
Toro is among my favorite and most complete works, you can read my thoughts on its retirement in my May article.