Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FileLock as a decorator #127

Closed
hirschalter opened this issue Jan 3, 2022 · 6 comments
Closed

Use FileLock as a decorator #127

hirschalter opened this issue Jan 3, 2022 · 6 comments

Comments

@hirschalter
Copy link
Contributor

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

@gaborbernat
Copy link
Member

@hirschalter
Copy link
Contributor Author

@gaborbernat sorry, I meant as a context decorator.

@gaborbernat
Copy link
Member

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

@hirschalter
Copy link
Contributor Author

hirschalter commented Jan 3, 2022

@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

@hirschalter hirschalter changed the title Use FileLock as a context manager Use FileLock as a decorator Jan 3, 2022
@gaborbernat
Copy link
Member

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

hirschalter pushed a commit to hirschalter/py-filelock that referenced this issue Jan 3, 2022
hirschalter pushed a commit to hirschalter/py-filelock that referenced this issue Jan 3, 2022
@hirschalter
Copy link
Contributor Author

@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

hirschalter pushed a commit to hirschalter/py-filelock that referenced this issue Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants