Metadata-Version: 2.1
Name: lockorator
Version: 0.1
Summary: lock decorators
Home-page: https://github.com/Fak3/lockorator
Author: Roman Evstifeev
Author-email: someuniquename@gmail.com
License: MIT
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: OS Independent
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Android
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development
Classifier: Topic :: Utilities

This package provides decorators that will try to acquire lock before
calling decorated function.

Installation
------------

.. code:: bash

   pip install lockorator

Usage
-----

This package provides two flavours of lock decorators: redis and
asyncio. Both flavours have the same api.

Package ``lockorator.asyncio`` provides asyncio lock decorators, also
compatible with ``trio``.

Package ``lockorator.redis`` provides redis lock decorators.

To use redis locks, set ``LOCKORATOR_REDIS_URL`` in your environment:

::

   export LOCKORATOR_REDIS_URL="redis://localhost:6379"

API
~~~

lock_or_exit
^^^^^^^^^^^^

Decorator. Before decorated function starts, try to acquire lock with
specified identifier. If lock is acquired successfully, proceed
executing the function. Otherwise, return immediately. The ``id``
argument can contain templated string, wich will be rendered with args
and kwargs, passed to the function.

Example:

.. code:: python

   from lockorator.asyncio import lock_or_exit

   @lock_or_exit('lock_work_{}')
   def workwork(x):
       pass

   workwork(3)  # Will try to acquire lock 'lock_work_3'

lock_wait
^^^^^^^^^

Decorator. Before decorated function starts, try to acquire lock with
specified identifier, waiting for ``waittime`` seconds if needed. If
lock is acquired successfully, proceed executing the function.
Otherwise, raise ``lockorator.TimeoutError``. The ``id`` argument can
contain templated string, wich will be rendered with args and kwargs,
passed to the function.

Example:

.. code:: python

   from lockorator.redis import lock_wait

   @lock_wait('lock_work_{}', waittime=4)
   def workwork(x):
       pass

   workwork(3)  # Will try to acquire lock 'lock_work_3' for 4 seconds


