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

What are the different locking mechanisms? #58

Closed
rayluo opened this issue Oct 7, 2020 · 2 comments
Closed

What are the different locking mechanisms? #58

rayluo opened this issue Oct 7, 2020 · 2 comments
Labels

Comments

@rayluo
Copy link
Contributor

rayluo commented Oct 7, 2020

Hi Rick, thanks for this portalocker library! It has been reliably serving us for quite a while. :-)

We recently encountered a cross-library issue likely caused by different locking mechanisms. Do you have some input on what are the pros and cons of the two different approaches, and why did you choose the one currently used in portalocker?

@wolph
Copy link
Owner

wolph commented Oct 9, 2020

A few years ago the library switched to LockFileEx to make sure we can have shared locks again: #30

Beyond that... I'm honestly not entirely sure what locking options Windows has for Python. On stackoverflow I can see a few different options, I wouldn't oppose switching methods if any of those would help: https://stackoverflow.com/questions/29344366/lock-file-for-access-on-windows

I have to say that I'm surprised that there are different incompatible locking methods on Windows, generally you would expect the kernel or the filesystem to implement that and all APIs call the same locking methods internally.

Are you sure it's not a behaviour difference? Looking at the message of bgavrilMS I see this:

If you run the python app first (i.e. create the lock from py), the .NET app waits for the lock to go away. If you run the .NET app first however, the python app crashes because it cannot acquire the lock.

That makes me think that .Net simply keeps waiting for a lock whereas the Python code has a timeout configured. This method is honestly a bit clunky but there is (was?) no good way to get a multi-platform locking timeout otherwise:
https://github.com/WoLpH/portalocker/blob/927d53ef8ba14662104999fcedb5a1e285aeb232/portalocker/utils.py#L153-L161

If you would set the timeout to some ridiculously large number you might get the same behaviour.

@rayluo
Copy link
Contributor Author

rayluo commented Oct 9, 2020

I have to say that I'm surprised that there are different incompatible locking methods on Windows, generally you would expect the kernel or the filesystem to implement that and all APIs call the same locking methods internally.

Yes, I'm equally surprised, too.

I wouldn't oppose switching methods if any of those would help: https://stackoverflow.com/questions/29344366/lock-file-for-access-on-windows

To be clear, I'm not currently suggesting a change from Portalocker. If Portalocker works fine in itself among its existing community, there is no motivation to change it.

Thanks for your input. We will give it more thoughts.

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

No branches or pull requests

2 participants