1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

portalocker for file locking check instead of fcntl. more portable on windows

This commit is contained in:
raffaele messuti 2016-12-26 10:27:20 +01:00
parent 0e414acfda
commit 524d9bfd26
2 changed files with 4 additions and 3 deletions

View File

@ -16,7 +16,7 @@ from collections import OrderedDict
from socket import gethostname from socket import gethostname
from io import BytesIO from io import BytesIO
import fcntl import portalocker
from pywb.utils.loaders import LimitReader, to_native_str from pywb.utils.loaders import LimitReader, to_native_str
from pywb.utils.bufferedreaders import BufferedReader from pywb.utils.bufferedreaders import BufferedReader
@ -384,7 +384,7 @@ class MultiFileWARCWriter(BaseWARCWriter):
def _close_file(self, fh): def _close_file(self, fh):
try: try:
fcntl.flock(fh, fcntl.LOCK_UN) portalocker.lock(fh, portalocker.LOCK_UN)
fh.close() fh.close()
except Exception as e: except Exception as e:
print(e) print(e)
@ -494,7 +494,7 @@ class MultiFileWARCWriter(BaseWARCWriter):
self.fh_cache.pop(dir_key, None) self.fh_cache.pop(dir_key, None)
elif is_new: elif is_new:
fcntl.flock(out, fcntl.LOCK_EX | fcntl.LOCK_NB) portalocker.lock(out, portalocker.LOCK_EX | portalocker.LOCK_NB)
self.fh_cache[dir_key] = (out, filename) self.fh_cache[dir_key] = (out, filename)
def iter_open_files(self): def iter_open_files(self):

View File

@ -87,6 +87,7 @@ setup(
'webencodings', 'webencodings',
'gevent==1.1.2', 'gevent==1.1.2',
'webassets==0.12.0', 'webassets==0.12.0',
'portalocker'
#'pyamf' #'pyamf'
], ],
dependency_links=[ dependency_links=[