Skip to content

Commit fdcf78f

Browse files
authored
Merge pull request #5 from claydugo/test_first_fix_later
Do not use thread-local lock behavior
2 parents 8d137ef + 23d0025 commit fdcf78f

File tree

6 files changed

+53
-6
lines changed

6 files changed

+53
-6
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
# Uncomment below once tests for filelock 3.11 are fixed
15-
# python-version: ['3.7', '3.9', '3.11']
16-
python-version: ['3.9']
14+
python-version: ['3.7', '3.9', '3.11']
15+
fail-fast: false
1716

1817
steps:
1918
- uses: actions/checkout@v1

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.0.6 (2023/04/18)
2+
3+
- Fix compatibility with filelock 3.12.0.
4+
- multiuserfilelock (all version) are incompatible with filelock 3.11.0.
5+
16
## 0.0.5 (2021/11/23)
27

38
- Ensure windows tests pass.

multiuserfilelock/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import shutil
77
import tempfile
88
from pathlib import Path
9+
import filelock
10+
from packaging.version import Version
911

1012
# Creating the locks directly in the /tmp dir on linux causes
1113
# many problems since the `/tmp` dir has the sticky bit enabled.
@@ -37,10 +39,14 @@ def __init__(self, *args, user=None, group=None, chmod=0o666, **kwargs):
3739
self._user = user
3840
self._group = group
3941
self._chmod = chmod
42+
43+
if Version(filelock.__version__) >= Version('3.12.0'):
44+
kwargs['thread_local'] = False
45+
4046
# Will create a ._lock_file object
4147
# but will not create the files on the file system
4248
super().__init__(*args, **kwargs)
43-
self._lock_file_path = Path(self._lock_file)
49+
self._lock_file_path = Path(self.lock_file)
4450
parent = self._lock_file_path.parent
4551
# Even though the "other write" permissions are enabled
4652
# it seems that the operating systems disables that for the /tmp dir

multiuserfilelock/tests/test_acquire.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from multiuserfilelock import MultiUserFileLock, Timeout
2+
from threading import Thread
3+
from queue import Queue
24
import pytest
35

46

@@ -26,3 +28,38 @@ def test_double_acquire(tmp_path):
2628

2729
lock1.release()
2830
lock2.acquire()
31+
32+
33+
def test_release_lock_from_different_thread(tmp_path):
34+
results = Queue()
35+
36+
def thread_lock_acquire(filename):
37+
lock = MultiUserFileLock(filename)
38+
lock.acquire()
39+
assert lock.is_locked
40+
results.put(lock)
41+
42+
def thread_lock_release(lock):
43+
lock.release()
44+
45+
lock_filename = tmp_path / 'test.lock'
46+
lock_thread = Thread(target=thread_lock_acquire, args=(lock_filename,))
47+
48+
lock_thread.start()
49+
lock_thread.join(timeout=1)
50+
assert not lock_thread.is_alive()
51+
lock = results.get(timeout=1)
52+
assert lock.is_locked
53+
54+
lock_thread = Thread(target=thread_lock_release, args=(lock,))
55+
lock_thread.start()
56+
lock_thread.join(timeout=1)
57+
assert not lock_thread.is_alive()
58+
assert not lock.is_locked
59+
60+
lock_thread2 = Thread(target=thread_lock_acquire, args=(lock_filename,))
61+
lock_thread2.start()
62+
lock_thread2.join(timeout=1)
63+
assert not lock_thread2.is_alive()
64+
lock2 = results.get(timeout=1)
65+
assert lock2.is_locked

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
filelock
1+
filelock !=3.11.0

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
license='BSD',
1313
python_requires='>=3.7',
1414
install_requires=[
15-
'filelock',
15+
'filelock!=3.11.0',
1616
],
1717
packages=find_packages(),
1818
cmdclass=versioneer.get_cmdclass(),

0 commit comments

Comments
 (0)