Acquire the lock, if possible. If the lock is in use, it check again every `wait` seconds. It does this until it either gets the lock or exceeds `timeout` number of seconds, in which case it throws an exception.
(self)
| 236 | self.delay = delay |
| 237 | |
| 238 | def acquire(self): |
| 239 | """ Acquire the lock, if possible. If the lock is in use, it check again |
| 240 | every `wait` seconds. It does this until it either gets the lock or |
| 241 | exceeds `timeout` number of seconds, in which case it throws |
| 242 | an exception. |
| 243 | """ |
| 244 | if self.is_locked: |
| 245 | return |
| 246 | |
| 247 | start_time = time.time() |
| 248 | while True: |
| 249 | try: |
| 250 | self.fd = os.open(self.lockfile, os.O_CREAT|os.O_EXCL|os.O_RDWR) |
| 251 | break; |
| 252 | except OSError as e: |
| 253 | if e.errno != errno.EEXIST: |
| 254 | raise |
| 255 | |
| 256 | if (time.time() - start_time) >= self.timeout: |
| 257 | raise FileLockException("Timeout occured.") |
| 258 | time.sleep(self.delay) |
| 259 | self.is_locked = True |
| 260 | |
| 261 | def release(self): |
| 262 | """ Get rid of the lock by deleting the lockfile. |
no test coverage detected