From 25c0accc3cd7820945b7f033304096e7b56b714a Mon Sep 17 00:00:00 2001 From: vbanos Date: Sat, 28 Oct 2017 21:13:23 +0300 Subject: [PATCH] Swap fcntl.flock with fcntl.lockf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Linux, `fcntl.flock` is implemented with `flock(2)`, and `fcntl.lockf` is implemented with `fcntl(2)` — they are not compatible. Java `lock()` appears to be `fcntl(2)`. So, other Java programs working with these files work correctly only with `fcntl.lockf`. `warcprox` MUST use `fcntl.lockf` --- tests/test_writer.py | 2 +- warcprox/writer.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_writer.py b/tests/test_writer.py index 8aedc7d..444909f 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -24,7 +24,7 @@ def lock_file(queue, filename): """ try: fi = open(filename, 'ab') - fcntl.flock(fi, fcntl.LOCK_EX | fcntl.LOCK_NB) + fcntl.lockf(fi, fcntl.LOCK_EX | fcntl.LOCK_NB) fi.close() queue.put('1') except IOError: diff --git a/warcprox/writer.py b/warcprox/writer.py index a3e24c6..7a1032a 100644 --- a/warcprox/writer.py +++ b/warcprox/writer.py @@ -74,7 +74,7 @@ class WarcWriter: self.logger.info('closing %s', self._f_finalname) if self._f_open_suffix == '': try: - fcntl.flock(self._f, fcntl.LOCK_UN) + fcntl.lockf(self._f, fcntl.LOCK_UN) except IOError as exc: self.logger.error('could not unlock file %s (%s)', self._fpath, exc) @@ -106,7 +106,7 @@ class WarcWriter: # file lock. if self._f_open_suffix == '': try: - fcntl.flock(self._f, fcntl.LOCK_EX | fcntl.LOCK_NB) + fcntl.lockf(self._f, fcntl.LOCK_EX | fcntl.LOCK_NB) except IOError as exc: self.logger.error('could not lock file %s (%s)', self._fpath, exc)