harlowja / fasteners

A python package that provides useful locks.
Apache License 2.0
246 stars 45 forks source link

Introduce native OS-supported shared/exclusive locking on the filesystem #41

Closed vector-of-bool closed 3 years ago

vector-of-bool commented 4 years ago

The existing interprocess locking doesn't exposed shared lock ownership (read/write locking). This implements shared and exclusive locks using the native APIs rather than the limited APIs exposed by the Python stdlib.

memsharded commented 4 years ago

This would be a very useful feature for us. We have been suffering from stalled locks when some process dies, and these locks will avoid it.

psarka commented 3 years ago

Hi @vector-of-bool, I missed your PR earlier, so I covered the shared/exclusive locks in https://github.com/harlowja/fasteners/pull/50

However, I really liked your approach to replace pywin32 by vendored code snippets, so I took them from your PR and added here: https://github.com/harlowja/fasteners/pull/57.

All the tests pass, but maybe you could take an extra look, to check if it is ok? In particular, after the failed lock attempt you were checking for error code ERROR_IO_PENDING = 997, while I saw other code snippets checking for ERROR_LOCK_VIOLATION=33 (which I can trigger, so it seems to work).