Skip to content

Commit a6c8fab

Browse files
Fix misspelled keyword argument poll_interval for method acquire (#119)
Co-authored-by: Bernát Gábor <gaborjbernat@gmail.com>
1 parent 73631be commit a6c8fab

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

docs/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
=========
33

4+
v3.4.0 (2021-11-16)
5+
-------------------
6+
- Add correct spelling of poll interval parameter for :meth:`acquire <filelock.BaseFileLock.acquire>` method, raise
7+
deprecation warning when using the misspelled form :pr:`119` - by :user:`XuehaiPan`.
8+
49
v3.3.2 (2021-10-29)
510
-------------------
611
- Accept path types (like ``pathlib.Path`` and ``pathlib.PurePath``) in the constructor for ``FileLock`` objects.

src/filelock/_api.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import os
33
import time
4+
import warnings
45
from abc import ABC, abstractmethod
56
from threading import Lock
67
from types import TracebackType
@@ -106,13 +107,19 @@ def is_locked(self) -> bool:
106107
"""
107108
return self._lock_file_fd is not None
108109

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:
110116
"""
111117
Try to acquire the file lock.
112118
113119
:param timeout: maximum wait time for acquiring the lock, ``None`` means use the default :attr:`~timeout` is and
114120
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
116123
:raises Timeout: if fails to acquire lock within the timeout period
117124
:return: a context object that will unlock the file when the context is exited
118125
@@ -131,15 +138,19 @@ def acquire(self, timeout: Optional[float] = None, poll_intervall: float = 0.05)
131138
132139
.. versionchanged:: 2.0.0
133140
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.
137143
138144
"""
139145
# Use the default timeout, if no timeout is provided.
140146
if timeout is None:
141147
timeout = self.timeout
142148

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+
143154
# Increment the number right at the beginning. We can still undo it, if something fails.
144155
with self._thread_lock:
145156
self._lock_counter += 1
@@ -162,8 +173,8 @@ def acquire(self, timeout: Optional[float] = None, poll_intervall: float = 0.05)
162173
raise Timeout(self._lock_file)
163174
else:
164175
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)
167178
except BaseException: # Something did go wrong, so decrement the counter.
168179
with self._thread_lock:
169180
self._lock_counter = max(0, self._lock_counter - 1)

tests/test_filelock.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,12 @@ def test_cleanup_soft_lock(tmp_path: Path) -> None:
350350
with lock:
351351
assert lock_path.exists()
352352
assert not lock_path.exists()
353+
354+
355+
@pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock])
356+
def test_poll_intervall_deprecated(lock_type: Type[BaseFileLock], tmp_path: Path) -> None:
357+
lock_path = tmp_path / "a"
358+
lock = lock_type(str(lock_path))
359+
360+
with pytest.deprecated_call(match="use poll_interval instead of poll_intervall"):
361+
lock.acquire(poll_intervall=0.05)

0 commit comments

Comments
 (0)