Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def pex_lockfile(basepath, uniquedir):
# Acquire the lockfile.
lockfile_path = os.path.join(basepath, '.lock-%s' % uniquedir)
lockfile = open(lockfile_path, "a+")
# Block until we can acquire the lockfile.
portalocker.lock(lockfile, portalocker.LOCK_EX)
lockfile.seek(0)
yield lockfile
portalocker.lock(lockfile, portalocker.LOCK_UN)
def _close_file(self, fh):
try:
if os.name != 'nt':
portalocker.lock(fh, portalocker.LOCK_UN)
return True
except Exception as e:
print(e)
return False
finally:
no_except_close(fh)
def __exit__(self, exc_type, exc_val, exc_tb):
if self.gpu_id is not None:
logger.info("Releasing GPU {}.".format(self.gpu_id))
if self.lock_file is not None:
if self._acquired_lock:
portalocker.lock(self.lock_file, portalocker.LOCK_UN)
self.lock_file.close()
os.remove(self.lockfile_path)