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