tox-dev / filelock

A platform-independent file lock for Python.

Home Page:https://py-filelock.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use FileLock as a decorator

hirschalter opened this issue · comments

Should be possible by inheriting from contextlib.ContextDecorator. What's required to contribute to the project?

@gaborbernat sorry, I meant as a context decorator.

Can you give an example of where, how and why you would want this?

@FileLock(lock_file_path)
def function_that_must_not_run_in_parallel():
    ...

I am using this for a regression test, where if I have multiple instances running on the same machine they interfere with each other. My current usage is:

class _FileLockDecorator(filelock.FileLock, contextlib.ContextDecorator):
    pass

@_FileLockDecorator(lock_file_path)
def run_regression():
    ...

Thanks

Sure, put in a PR with tests, documentation and changelog entry 👌

@gaborbernat I made a PR with tests, documentation (I added an example in the tutorial in index.rst) & a changelog entry

Is there anything else I should add?

#128

Thanks