From 4ae44ac91812c1db765b0a8b3b2e280e5494d3a7 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Wed, 6 Jan 2016 11:37:44 -0800 Subject: [PATCH] Add interprocess warning and try-lock example Part of issue #11 --- doc/source/examples.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/doc/source/examples.rst b/doc/source/examples.rst index 8110ac7..15bb341 100644 --- a/doc/source/examples.rst +++ b/doc/source/examples.rst @@ -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")