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 os.path.exists(self.portfname): os.remove(self.portfname) if self.statusfile: self.statusfile.write('_cleanup: logger stopping.\n') self.statusfile.flush() self.statusfile.close() self.statusfile = None DaemonProcess._cleanup(self)
def __init__(self, pidfname, logfname, statusfname, portfname, workdir, delim, ppid): """ Base logger process constructor. @param pidfname Process id file name. @param logfname Log file name. @param statusfname Status file name. @param portfname Port file name. @param workdir The work directory. @param delim 2-element delimiter to indicate traffic from the driver in the logfile. @param ppid Parent process ID, used to self destruct when parents die in test cases. """ DaemonProcess.__init__(self, pidfname, logfname, workdir) self.server_port = None self.driver_server_sock = None self.driver_sock = None self.driver_addr = None self.delim = delim self.statusfname = workdir + statusfname self.ppid = ppid self.last_parent_check = None self.portfname = workdir + portfname