1
1
import logging
2
2
import os
3
3
import time
4
+ import warnings
4
5
from abc import ABC , abstractmethod
5
6
from threading import Lock
6
7
from types import TracebackType
@@ -106,13 +107,19 @@ def is_locked(self) -> bool:
106
107
"""
107
108
return self ._lock_file_fd is not None
108
109
109
- def acquire (self , timeout : Optional [float ] = None , poll_intervall : float = 0.05 ) -> AcquireReturnProxy :
110
+ def acquire (
111
+ self ,
112
+ timeout : Optional [float ] = None ,
113
+ poll_interval : float = 0.05 ,
114
+ poll_intervall : Optional [float ] = None ,
115
+ ) -> AcquireReturnProxy :
110
116
"""
111
117
Try to acquire the file lock.
112
118
113
119
:param timeout: maximum wait time for acquiring the lock, ``None`` means use the default :attr:`~timeout` is and
114
120
if ``timeout < 0``, there is no timeout and this method will block until the lock could be acquired
115
- :param poll_intervall: interval of trying to acquire the lock file
121
+ :param poll_interval: interval of trying to acquire the lock file
122
+ :param poll_intervall: deprecated, kept for backwards compatibility, use ``poll_interval`` instead
116
123
:raises Timeout: if fails to acquire lock within the timeout period
117
124
:return: a context object that will unlock the file when the context is exited
118
125
@@ -131,15 +138,19 @@ def acquire(self, timeout: Optional[float] = None, poll_intervall: float = 0.05)
131
138
132
139
.. versionchanged:: 2.0.0
133
140
134
- This method returns now a *proxy* object instead of *self*,
135
- so that it can be used in a with statement without side effects.
136
-
141
+ This method returns now a *proxy* object instead of *self*, so that it can be used in a with statement \
142
+ without side effects.
137
143
138
144
"""
139
145
# Use the default timeout, if no timeout is provided.
140
146
if timeout is None :
141
147
timeout = self .timeout
142
148
149
+ if poll_intervall is not None :
150
+ msg = "use poll_interval instead of poll_intervall"
151
+ warnings .warn (msg , DeprecationWarning )
152
+ poll_interval = poll_intervall
153
+
143
154
# Increment the number right at the beginning. We can still undo it, if something fails.
144
155
with self ._thread_lock :
145
156
self ._lock_counter += 1
@@ -162,8 +173,8 @@ def acquire(self, timeout: Optional[float] = None, poll_intervall: float = 0.05)
162
173
raise Timeout (self ._lock_file )
163
174
else :
164
175
msg = "Lock %s not acquired on %s, waiting %s seconds ..."
165
- _LOGGER .debug (msg , lock_id , lock_filename , poll_intervall )
166
- time .sleep (poll_intervall )
176
+ _LOGGER .debug (msg , lock_id , lock_filename , poll_interval )
177
+ time .sleep (poll_interval )
167
178
except BaseException : # Something did go wrong, so decrement the counter.
168
179
with self ._thread_lock :
169
180
self ._lock_counter = max (0 , self ._lock_counter - 1 )
0 commit comments