30
30
tmpdir = Path (tempfile .gettempdir ())
31
31
32
32
33
- class MultiUserFileLock ( FileLock ) :
33
+ class MultiUserFileLock :
34
34
def __init__ (self , * args , user = None , group = None , chmod = 0o666 , ** kwargs ):
35
35
if os .name == 'nt' :
36
36
self ._user = None
@@ -45,8 +45,8 @@ def __init__(self, *args, user=None, group=None, chmod=0o666, **kwargs):
45
45
46
46
# Will create a ._lock_file object
47
47
# but will not create the files on the file system
48
- super (). __init__ (* args , ** kwargs )
49
- self ._lock_file_path = Path (self .lock_file )
48
+ self . _filelock = FileLock (* args , ** kwargs )
49
+ self ._lock_file_path = Path (self ._filelock . lock_file )
50
50
parent = self ._lock_file_path .parent
51
51
# Even though the "other write" permissions are enabled
52
52
# it seems that the operating systems disables that for the /tmp dir
@@ -60,7 +60,7 @@ def __init__(self, *args, user=None, group=None, chmod=0o666, **kwargs):
60
60
shutil .chown (parent , user = self ._user )
61
61
62
62
def acquire (self , * args , ** kwargs ):
63
- super () .acquire (* args , ** kwargs )
63
+ self . _filelock .acquire (* args , ** kwargs )
64
64
# once the lock has been acquired, we are more guaranteed that the
65
65
# _lock_file exists
66
66
if self ._chmod :
@@ -83,6 +83,41 @@ def acquire(self, *args, **kwargs):
83
83
if self ._lock_file_path .owner () != self ._user :
84
84
shutil .chown (self ._lock_file_path , user = self ._user )
85
85
86
+ @property
87
+ def is_locked (self ):
88
+ return self ._filelock .is_locked
89
+
90
+ def release (self , * args , ** kwargs ):
91
+ self ._filelock .release (* args , ** kwargs )
92
+
93
+ def __enter__ (self ):
94
+ self .acquire ()
95
+ return self
96
+
97
+ def __exit__ (self , * args , ** kwargs ):
98
+ self .release ()
99
+
100
+
101
+ @property
102
+ def timeout (self ):
103
+ return self ._filelock .timeout
104
+
105
+ @timeout .setter
106
+ def timeout (self , value ):
107
+ self ._filelock .timeout = value
108
+
109
+ @property
110
+ def blocking (self ):
111
+ return self ._filelock .blocking
112
+
113
+ @blocking .setter
114
+ def blocking (self , value ):
115
+ self ._filelock .blocking = value
116
+
117
+ @property
118
+ def lock_file (self ):
119
+ return self ._filelock .lock_file
120
+
86
121
87
122
__all__ = [
88
123
'MultiUserFileLock' ,
0 commit comments