| 289 | self.kill_stale_locks = True |
| 290 | |
| 291 | def load(self): |
| 292 | try: |
| 293 | with self.path.open() as f: |
| 294 | data = json.load(f) |
| 295 | |
| 296 | # Just nuke the stale locks early on load |
| 297 | if self.kill_stale_locks: |
| 298 | for key in (SHARED, EXCLUSIVE): |
| 299 | try: |
| 300 | entries = data[key] |
| 301 | except KeyError: |
| 302 | continue |
| 303 | elements = set() |
| 304 | for host, pid, thread in entries: |
| 305 | if platform.process_alive(host, pid, thread): |
| 306 | elements.add((host, pid, thread)) |
| 307 | else: |
| 308 | logger.warning( |
| 309 | "Removed stale %s roster lock for host %s pid %d thread %d.", key, host, pid, thread |
| 310 | ) |
| 311 | data[key] = list(elements) |
| 312 | except (FileNotFoundError, ValueError): |
| 313 | # no or corrupt/empty roster file? |
| 314 | data = {} |
| 315 | return data |
| 316 | |
| 317 | def save(self, data): |
| 318 | with self.path.open("w") as f: |