Add interprocess warning and try-lock example

Part of issue #11
This commit is contained in:
Joshua Harlow 2016-01-06 11:37:44 -08:00
parent 5e9ce01c3b
commit 4ae44ac918
1 changed files with 25 additions and 0 deletions

View File

@ -9,6 +9,13 @@ Interprocess locks
Launch multiple of these at the same time to see the lock(s) in action.
.. warning::
There are no guarantees regarding usage by multiple threads in a
single process with these locks (you will have to ensure single process
safety yourself using traditional thread based locks). In other words this
lock works **only** between processes.
.. code-block:: python
import time
@ -143,3 +150,21 @@ Multi-lock decorator
o = NotThreadSafeThing()
o.do_something()
--------
Try lock
--------
.. code-block:: python
import threading
import fasteners
t = threading.Lock()
with fasteners.try_lock(t) as gotten:
if gotten:
print("I got the lock")
else:
print("I did not get the lock")