Swap fcntl.flock with fcntl.lockf

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`
This commit is contained in:
vbanos 2017-10-28 21:13:23 +03:00
parent eda3da1db7
commit 25c0accc3c
2 changed files with 3 additions and 3 deletions

View File

@ -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:

View File

@ -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)