Skip to content

Commit

Permalink
Refactor shutdown and assert_peers_healthy functions 🎯
Browse files Browse the repository at this point in the history
- `daemon.py`: Adjust shutdown order and remove race condition.
- `healthy.py`: Loosen peer health check assertions.
- `pyproject.toml`: Bump version from 0.16.1 to 0.16.2.

Improved shutdown sequence to handle exceptions better. Relaxed peer health
check conditions to support more configurations. Version update reflects
enhancements.
  • Loading branch information
horta committed Dec 5, 2024
1 parent 121877c commit fb2d72f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
13 changes: 6 additions & 7 deletions h3daemon/h3daemon/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def shutdown(x: psutil.Process, force: bool):
with suppress(psutil.NoSuchProcess):
if force:
x.kill()
x.wait()
else:
x.terminate()
try:
Expand Down Expand Up @@ -71,10 +70,10 @@ def spawn(cls, hmmfile: HMMFile, cport: int = 0, wport: int = 0):
assert_peers_healthy(master, worker)
except Exception as exception:
debug_exception(exception)
if master:
shutdown(master.process, force=True)
if worker:
shutdown(worker.process, force=True)
if master:
shutdown(master.process, force=True)
raise exception

return cls(master, worker, None)
Expand All @@ -100,11 +99,11 @@ def possess(cls, pidfile: PIDLockFile):
return cls(master, worker, process)

def shutdown(self, force=False):
if self._master is not None:
shutdown(self._master.process, force)

if self._worker is not None:
shutdown(self._worker.process, force)
shutdown(self._worker.process, True)

if self._master is not None:
shutdown(self._master.process, True)

if self._process is not None:
shutdown(self._process, force)
Expand Down
8 changes: 4 additions & 4 deletions h3daemon/h3daemon/healthy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ def assert_peers_healthy(master: Master, worker: Worker):
worker_lport = worker.local_established_ports()
worker_rport = worker.remote_established_ports()

assert len(master_lport) == 1
assert len(master_lport) >= 1
assert len(worker_rport) == 1
assert master_lport[0] == worker_rport[0]
assert len(master_rport) == 1
assert worker_rport[0] in master_lport
assert len(master_rport) >= 1
assert len(worker_lport) == 1
assert master_rport[0] == worker_lport[0]
assert worker_lport[0] in master_rport
assert len(master_listen) == 2
master_ports = set(master_listen)
assert len(master_ports) == 2
Expand Down
2 changes: 1 addition & 1 deletion h3daemon/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "h3daemon"
version = "0.16.1"
version = "0.16.2"
description = "HMMER server"
authors = ["Danilo Horta <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit fb2d72f

Please sign in to comment.