Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion msal_extensions/cache_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import errno
import portalocker
from distutils.version import LooseVersion


class CrossPlatLock(object):
Expand All @@ -12,6 +13,8 @@ class CrossPlatLock(object):
"""
def __init__(self, lockfile_path):
self._lockpath = lockfile_path
# Support for passing through arguments to the open syscall was added in v1.4.0
open_kwargs = {'buffering': 0} if LooseVersion(portalocker.__version__) >= LooseVersion("1.4.0") else {}
self._lock = portalocker.Lock(
lockfile_path,
mode='wb+',
Expand All @@ -20,7 +23,7 @@ def __init__(self, lockfile_path):
# More information here:
# https://docs.python.org/3/library/fcntl.html#fcntl.lockf
flags=portalocker.LOCK_EX | portalocker.LOCK_NB,
buffering=0)
**open_kwargs)

def __enter__(self):
file_handle = self._lock.__enter__()
Expand Down