Skip to content

Commit

Permalink
Add tests for multiprocessing-driven hmmsearch and fix some exit …
Browse files Browse the repository at this point in the history
…conditions
  • Loading branch information
althonos committed Oct 14, 2024
1 parent 3d934cf commit 2bcb411
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/pyhmmer/hmmer/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,11 @@ def run(self) -> None:
def is_killed(self) -> bool:
try:
return self.kill_switch.is_set()
except BrokenPipeError:
except BrokenPipeError: # the connection was closed already
return True
except ConnectionResetError:
except ConnectionResetError: # the connection was closed already
return True
except FileNotFoundError: # the Event manager has been closed already
return True

def kill(self) -> None:
Expand Down
2 changes: 2 additions & 0 deletions src/pyhmmer/hmmer/_jackhmmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ def _new_worker(
query_count: "multiprocessing.Value[int]", # type: ignore
kill_switch: threading.Event,
) -> _JACKHMMERWorker[_I]:
if self.backend != "threading":
raise ValueError(f"Invalid backend for `jackhmmer`: {self.backend!r}")
return _JACKHMMERWorker(
self.targets,
query_queue,
Expand Down
14 changes: 13 additions & 1 deletion src/pyhmmer/tests/test_hmmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,19 @@ def get_hits(self, hmm, seqs):
def test_no_queries(self):
with self.seqs_file("938293.PRJEB85.HG003687", digital=True) as seqs_file:
seqs = list(seqs_file)
hits = pyhmmer.hmmsearch([], seqs)
hits = pyhmmer.hmmsearch([], seqs, cpus=1)
self.assertIs(None, next(hits, None))


class TestHmmsearchProcess(TestHmmsearch, unittest.TestCase):
def get_hits(self, hmm, seqs):
return list(pyhmmer.hmmsearch(hmm, seqs, cpus=2, backend="multiprocessing"))[0]

@unittest.skipUnless(resource_files, "importlib.resources not available")
def test_no_queries(self):
with self.seqs_file("938293.PRJEB85.HG003687", digital=True) as seqs_file:
seqs = list(seqs_file)
hits = pyhmmer.hmmsearch([], seqs, cpus=2, backend="multiprocessing")
self.assertIs(None, next(hits, None))


Expand Down

0 comments on commit 2bcb411

Please sign in to comment.