Whole file
trbs/pid
The author described this change as “fix atexit registration is never done #24”. It counts as a record because the check below fails on the code as it stood at 62e5f4a28 and passes on 4a313cea5, with nothing else changed between the two runs.
Projecttrbs/pid
Fix saved2019-07-04
Sharing licenceApache-2.0 · LICENSE
Change size+9 −7
What the code was meant to do, written into the code itself as a save note
fix atexit registration is never done #24
The change
| 34 | 34 | ||
| 35 | 35 | ||
| 36 | 36 | class PidFile(object): | |
| 37 | - | __slots__ = ("pid", "pidname", "piddir", "enforce_dotpid_postfix", | |
| 38 | - | "register_term_signal_handler", "register_atexit", "filename", | |
| 39 | - | "fh", "lock_pidfile", "chmod", "uid", "gid", "force_tmpdir", | |
| 40 | - | "allow_samepid", "_logger", "_is_setup", "_already_removed") | |
| 37 | + | __slots__ = ( | |
| 38 | + | "pid", "pidname", "piddir", "enforce_dotpid_postfix", | |
| 39 | + | "register_term_signal_handler", "register_atexit", "filename", | |
| 40 | + | "fh", "lock_pidfile", "chmod", "uid", "gid", "force_tmpdir", | |
| 41 | + | "allow_samepid", "_logger", "_is_setup", "_already_removed", | |
| 42 | + | ) | |
| 41 | 43 | ||
| 42 | 44 | def __init__(self, pidname=None, piddir=None, enforce_dotpid_postfix=True, | |
| 43 | 45 | register_term_signal_handler='auto', register_atexit=True, | |
| ⋯ | |||
| 78 | 80 | self.filename = self._make_filename() | |
| 79 | 81 | self._register_term_signal() | |
| 80 | 82 | ||
| 83 | + | if self.register_atexit: | |
| 84 | + | atexit.register(self.close) | |
| 85 | + | ||
| 81 | 86 | # setup should only be performed once | |
| 82 | 87 | self._is_setup = True | |
| 83 | 88 | ||
| ⋯ | |||
| 187 | 192 | self.fh.flush() | |
| 188 | 193 | self.fh.seek(0) | |
| 189 | 194 | self._already_removed = False | |
| 190 | - | ||
| 191 | - | if self.register_atexit and not self._is_setup: | |
| 192 | - | atexit.register(self.close) | |
| 193 | 195 | ||
| 194 | 196 | def close(self, fh=None, cleanup=None): | |
| 195 | 197 | self.logger.debug("%r closing pidfile: %s", self, self.filename) | |
The check that tells the two apart
fail→pass·tests/test_pid.py::test_register_atexit_true
Check file tests/test_pid.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it62e5f4a289ede9e55887e5279ca50a5063034dcd
Broken version dated2019-03-05
Modulepid.__init__
Units changedPidFile
Fingerprint021bc100f68b3982
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.