Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __enter__(self):
current_time = call_time = time.time()
while call_time + self._timeout > current_time:
self._lockfile = open(self._filepath, 'w')
try:
portalocker.lock(self._lockfile, portalocker.constants.LOCK_NB | portalocker.constants.LOCK_EX)
return self
except portalocker.exceptions.LockException:
pass
current_time = time.time()
check_interval = self._check_interval if self._timeout > self._check_interval else self._timeout
time.sleep(check_interval)
raise RuntimeError('Timeout was reached')