Read and return the current pid.
(self)
| 161 | __exit__ = release |
| 162 | |
| 163 | def read_pid(self): |
| 164 | """Read and return the current pid.""" |
| 165 | with ignore_errno('ENOENT'): |
| 166 | with open(self.path) as fh: |
| 167 | line = fh.readline() |
| 168 | if line.strip() == line: # must contain '\n' |
| 169 | raise ValueError( |
| 170 | f'Partial or invalid pidfile {self.path}') |
| 171 | |
| 172 | try: |
| 173 | return int(line.strip()) |
| 174 | except ValueError: |
| 175 | raise ValueError( |
| 176 | f'pidfile {self.path} contents invalid.') |
| 177 | |
| 178 | def remove(self): |
| 179 | """Remove the lock.""" |