Read and return the current pid.
(self)
| 170 | __exit__ = release |
| 171 | |
| 172 | def read_pid(self): |
| 173 | """Read and return the current pid.""" |
| 174 | with ignore_errno('ENOENT'): |
| 175 | with open(self.path) as fh: |
| 176 | line = fh.readline() |
| 177 | if line.strip() == line: # must contain '\n' |
| 178 | raise ValueError( |
| 179 | f'Partial or invalid pidfile {self.path}') |
| 180 | |
| 181 | try: |
| 182 | return int(line.strip()) |
| 183 | except ValueError: |
| 184 | raise ValueError( |
| 185 | f'pidfile {self.path} contents invalid.') |
| 186 | |
| 187 | def remove(self): |
| 188 | """Remove the lock.""" |