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

Allow multiple readers #58

Open
cppntn opened this issue Jan 24, 2020 · 4 comments
Open

Allow multiple readers #58

cppntn opened this issue Jan 24, 2020 · 4 comments

Comments

@cppntn
Copy link

cppntn commented Jan 24, 2020

Is there a way to add an argument to the LockFile class, such as "writer" or "reader", in order to:

  1. allow multiple readings between processes and threads (like with LockFile("file.txt", mode="reader"):) avoiding writing

  2. not allow readings while writing (like with LockFile("file.txt", mode="writer"):)

Thanks

Edit: the operations are not referred to the file "file.txt", that file is just used as a locker.

@chrysn
Copy link

chrysn commented Jan 24, 2020

For the benefit of searchability, this is also called a readers-writers-lock, or an RW-lock.

@hmeine
Copy link

hmeine commented Feb 13, 2020

I would be interested in the same thing.

Implementation-wise, it would be possible to do this on top of the current classes: One could have a regular filelock around a shared file that contains the current number of readers / a writer flag. However, that would require three files, and some code would need to compose three corresponding filenames. Hence, if it was possible to have such a simple API as suggested above, that would be welcome!

@hmeine
Copy link

hmeine commented Feb 13, 2020

Are there alternative terms to be considered? I like mode = "reader" / "writer", but could also imagine "shared" / "exclusive", for instance.

@gaborbernat
Copy link
Member

Hello, if you make a PR for this (with tests) we would be happy to review, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants