def _cleanup(self): """ Cleanup function prior to logger exit. Close comms, status file and call DaemonProcess cleanup. This is called by the DaemonProcess SIGTERM handler if termination occurs due to signal, or by atexit handler if the run loop concludes normally. """ self._close_device_comms() self._close_driver_comms() if self.statusfile: self.statusfile.write('_cleanup: logger stopping.\n') self.statusfile.flush() self.statusfile.close() self.statusfile = None DaemonProcess._cleanup(self)