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?
This is already possible https://github.com/tox-dev/py-filelock/blob/main/src/filelock/_api.py#L207-L229
@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?
Thanks