def lockfile(lockfile_name, lock_wait_timeout=-<NUM_LIT:1>):
def decorator(func):<EOL><INDENT>@wraps(func)<EOL>def wrapper(*args, **kwargs):<EOL><INDENT>lock = FileLock(lockfile_name)<EOL>try:<EOL><INDENT>lock.acquire(lock_wait_timeout)<EOL><DEDENT>except AlreadyLocked:<EOL><INDENT>return<EOL><DEDENT>except LockTimeout:<EOL><INDENT>return<EOL><DEDENT>try:<EOL><INDENT>result = func(*args, **kwargs)<EOL><DEDENT>finally:<EOL><INDENT>lock.release()<EOL><DEDENT>return result<EOL><DEDENT>return wrapper<EOL><DEDENT>return decorator<EOL>
Only runs the method if the lockfile is not acquired.

You should create a setting ``LOCKFILE_PATH`` which points to
``/home/username/tmp/``.

In your management command, use it like so::

    LOCKFILE = os.path.join(
        settings.LOCKFILE_FOLDER, 'command_name')

    class Command(NoArgsCommand):
        @lockfile(LOCKFILE)
        def handle_noargs(self, **options):
            # your command here

:lockfile_name: A unique name for a lockfile that belongs to the wrapped
  method.
:lock_wait_timeout: Seconds to wait if lockfile is acquired. If ``-1`` we
  will not wait and just quit.