| 222 | return False |
| 223 | |
| 224 | def write_pid(self): |
| 225 | pid = os.getpid() |
| 226 | content = f'{pid}\n' |
| 227 | |
| 228 | pidfile_fd = os.open(self.path, PIDFILE_FLAGS, PIDFILE_MODE) |
| 229 | pidfile = os.fdopen(pidfile_fd, 'w') |
| 230 | try: |
| 231 | pidfile.write(content) |
| 232 | # flush and sync so that the re-read below works. |
| 233 | pidfile.flush() |
| 234 | try: |
| 235 | os.fsync(pidfile_fd) |
| 236 | except AttributeError: # pragma: no cover |
| 237 | pass |
| 238 | finally: |
| 239 | pidfile.close() |
| 240 | |
| 241 | rfh = open(self.path) |
| 242 | try: |
| 243 | if rfh.read() != content: |
| 244 | raise LockFailed( |
| 245 | "Inconsistency: Pidfile content doesn't match at re-read") |
| 246 | finally: |
| 247 | rfh.close() |
| 248 | |
| 249 | |
| 250 | PIDFile = Pidfile # XXX compat alias |