more pid start rework

This commit is contained in:
itdominator 2024-01-08 20:01:14 -06:00
parent d4a38c3e14
commit bff6988297
2 changed files with 16 additions and 14 deletions

View File

@ -28,6 +28,7 @@ class Application:
self.setup_debug_hook() self.setup_debug_hook()
Window(args, unknownargs).main() Window(args, unknownargs).main()
def load_ipc(self, args, unknownargs): def load_ipc(self, args, unknownargs):
ipc_server = IPCServer() ipc_server = IPCServer()
self.ipc_realization_check(ipc_server) self.ipc_realization_check(ipc_server)

View File

@ -11,7 +11,8 @@ import inspect
class StartCheckMixin: class StartCheckMixin:
def is_dirty_start(self) -> bool: return self._dirty_start def is_dirty_start(self) -> bool:
return self._dirty_start
def clear_pid(self): def clear_pid(self):
if not self.is_trace_debug(): if not self.is_trace_debug():
@ -23,28 +24,28 @@ class StartCheckMixin:
self._print_pid(pid) self._print_pid(pid)
return return
if not os.path.exists(self._PID_FILE): if os.path.exists(self._PID_FILE):
self._write_new_pid() with open(self._PID_FILE, "r") as f:
else: pid = f.readline().strip()
with open(self._PID_FILE, "r") as _pid:
pid = _pid.readline().strip()
if pid not in ("", None): if pid not in ("", None):
self._check_alive_status(int(pid)) if self.is_pid_alive( int(pid) ):
else: print("PID file exists and PID is alive... Letting downstream errors (sans debug args) handle app closure propigation.")
self._write_new_pid() return
self._write_new_pid()
""" Check For the existence of a unix pid. """ """ Check For the existence of a unix pid. """
def _check_alive_status(self, pid): def is_pid_alive(self, pid):
print(f"PID Found: {pid}") print(f"PID Found: {pid}")
try: try:
os.kill(pid, 0) os.kill(pid, 0)
except OSError: except OSError:
print(f"{app_name} PID exists but is not up; starting dirty...") print(f"{app_name} PID file exists but PID is irrelevant; starting dirty...")
self._dirty_start = True self._dirty_start = True
self._write_new_pid() return False
return
print("PID is alive... Let downstream errors (sans debug args) handle app closure propigation.") return True
def _write_new_pid(self): def _write_new_pid(self):
pid = os.getpid() pid = os.getpid()