diff --git a/README.md b/README.md index 9aeed09..c47eb7d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ilock v.1.0.3 +# ilock v.1.0.4 ## About @@ -62,6 +62,12 @@ with lock: ... ``` +### changelog: +v.1.0.4: +> Minor performance improvement for linux OS: + +> ```when no file location is set, it will use by default the OS memory directory structure``` + ## License diff --git a/ilock/__init__.py b/ilock/__init__.py index 0d223fe..21e67c3 100644 --- a/ilock/__init__.py +++ b/ilock/__init__.py @@ -7,6 +7,9 @@ import portalocker +#linux memory file directory, for better performance +MEMORY_FILE_DIRECTORY = '/dev/shm/' +TEMP_DIR = MEMORY_FILE_DIRECTORY if os.path.isdir(MEMORY_FILE_DIRECTORY) else gettempdir() class ILockException(Exception): pass @@ -17,7 +20,7 @@ def __init__(self, name, timeout=None, check_interval=0.25, reentrant=False, loc self._timeout = timeout if timeout is not None else 10 ** 8 self._check_interval = check_interval - lock_directory = gettempdir() if lock_directory is None else lock_directory + lock_directory = TEMP_DIR if lock_directory is None else lock_directory unique_token = sha256(name.encode()).hexdigest() self._filepath = os.path.join(lock_directory, 'ilock-' + unique_token + '.lock') @@ -55,8 +58,12 @@ def __exit__(self, exc_type, exc_val, exc_tb): return if sys.platform.startswith('linux'): - # In Linux you can delete a locked file - os.unlink(self._filepath) + try: + # In Linux you can delete a locked file + os.unlink(self._filepath) + except FileNotFoundError: + # this can happen very rarely + pass self._lockfile.close() diff --git a/setup.py b/setup.py index ee19c59..9575c18 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup -version = '1.0.3' +version = '1.0.4' setup( name='ilock',