Exemplo n.º 1
0
 def acquire(self):
     try:
         self._lock.acquire()
         self._acquired = True
     except (portalocker.AlreadyLocked, portalocker.LockException) as e:
         raise TimeoutError("Could not acquire lock '{filename}'.".format(
             filename=self.filename)) from e
Exemplo n.º 2
0
 def acquire(self):
     start = time.time()
     while True:
         try:
             self._fd = os.open(self.filename,
                                os.O_CREAT | os.O_RDWR | os.O_EXCL)
             return
         except OSError as err:
             if err.errno not in (errno.EEXIST, errno.EACCES):
                 raise
             elif time.time() - start >= self.timeout:
                 raise TimeoutError(
                     "Could not acquire lock '{filename}'.".format(
                         filename=self.filename))
             else:
                 time.sleep(self.poll)