Skip to content

Commit

Permalink
Handle macOS daemon issue and logging changes
Browse files Browse the repository at this point in the history
- `daemon.py`: Skip health check on macOS with platform check 🍏
- `daemonize.py`: Add debug logging to file and fix detach setting πŸ“
- Modify `spawn` function to pass and handle `detach` parameter πŸ”„

These changes address a compatibility issue with macOS, where the peer
health check was causing failures. By utilizing a platform check, macOS
subsequently bypasses this step. Additionally, logging aids debugging by
providing insights when the daemonize function is entered. Adjusting the
detach behavior in the `spawn` function ensures the daemon process is
initiated properly.
  • Loading branch information
horta committed Dec 5, 2024
1 parent 6b7f72d commit 1f46db4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion h3daemon/h3daemon/daemon.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import platform
import traceback
from contextlib import suppress

Expand Down Expand Up @@ -65,7 +66,8 @@ def spawn(cls, hmmfile: HMMFile, cport: int = 0, wport: int = 0):
worker = Worker(psutil.Popen(cmd))
worker.wait_for_readiness()

assert_peers_healthy(master, worker)
if platform.system() != "Darwin":
assert_peers_healthy(master, worker)
except Exception as exception:
debug_exception(exception)
if master:
Expand Down
10 changes: 6 additions & 4 deletions h3daemon/h3daemon/daemonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def daemonize(
stderr: Optional[Any] = None,
detach: Optional[bool] = None,
):
with open("/Users/horta/code/deciphon/gui/daemonize.txt", "a") as f:
f.write("ENTROU\n")
ensure_pressed(hmmfile)
fin = open(stdin, "r") if stdin else stdin
fout = open(stdout, "w+") if stdout else stdout
Expand All @@ -31,7 +33,7 @@ def daemonize(
with DaemonContext(
working_directory=str(hmmfile.path.parent),
pidfile=pidfile,
detach_process=True,
detach_process=detach,
stdin=fin,
stdout=fout,
stderr=ferr,
Expand All @@ -49,6 +51,7 @@ def spawn(
stdin: Optional[Any] = None,
stdout: Optional[Any] = None,
stderr: Optional[Any] = None,
detach: Optional[bool] = None,
force: Optional[bool] = False,
):
pidfile = create_pidfile(hmmfile.path)
Expand All @@ -58,8 +61,7 @@ def spawn(
x = Daemon.possess(pidfile)
x.shutdown(force=force)

args = (hmmfile, cport, wport, stdin, stdout, stderr)
p = Process(target=daemonize, args=args, daemon=True)
args = (hmmfile, cport, wport, stdin, stdout, stderr, detach)
p = Process(target=daemonize, args=args, daemon=False)
p.start()
p.join()
return pidfile

0 comments on commit 1f46db4

Please sign in to comment.