diff --git a/src/pyhmmer/hmmer/_base.py b/src/pyhmmer/hmmer/_base.py index 62d5c66..d0b8baa 100644 --- a/src/pyhmmer/hmmer/_base.py +++ b/src/pyhmmer/hmmer/_base.py @@ -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: diff --git a/src/pyhmmer/hmmer/_jackhmmer.py b/src/pyhmmer/hmmer/_jackhmmer.py index 93b873e..77970a0 100644 --- a/src/pyhmmer/hmmer/_jackhmmer.py +++ b/src/pyhmmer/hmmer/_jackhmmer.py @@ -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, diff --git a/src/pyhmmer/tests/test_hmmer.py b/src/pyhmmer/tests/test_hmmer.py index 9bf2bf7..8112993 100644 --- a/src/pyhmmer/tests/test_hmmer.py +++ b/src/pyhmmer/tests/test_hmmer.py @@ -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))