surfly/gevent — pull request #479 by yalon (2014-09-16 12:31:42+00:00)
Title: Added NativeFriendlyRLock to gevent.lock

Gevent is awesome. I use it in tons of projects and couldn't be happier. While gevent can be safely used in a (native) threaded application, there is no solution (that I'm aware of at least) to synchronize greenlets between different native threads. While this type of lock may seem not necessary at first, its necessity becomes apparent when there's a resource shared between different native threads such as a logging infrastructure that innocently holds a lock to synchronize log writes.

NativeFriendlyRLock (for lack of a better name) is an RLock that can be used across different native threads (e.g. Python's threading module) and greenlets. It provides a fair synchronization between threads/greenlets while keeping the "blocking" part gevent-friendly.

The commit adds the new lock type and a new test file that also tests fairness.

Your feedback (and hopefully pull request approval) is very appreciated :)