Skip to content

Commit

Permalink
Refactor progress bar context management
Browse files Browse the repository at this point in the history
  • Loading branch information
horta committed Feb 9, 2024
1 parent c49555b commit c93faa9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 1 addition & 4 deletions cli/deciphon/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,11 @@ def scan(
with H3Daemon(hmm, stdout=DEVNULL) as daemon:
params = Params(num_threads, multi_hits, hmmer3_compat)
scan = Scan(params, db)
with scan:
bar = Progress(scan, disabled=not progress)
bar.start()
with scan, Progress(scan, disabled=not progress):
scan.dial(daemon.port)
for seq in sequences:
scan.add(seq)
scan.run(snap)
bar.stop()
echo(
"Scan has finished successfully and "
f"results stored in '{snap.path}'."
Expand Down
7 changes: 7 additions & 0 deletions cli/deciphon/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ def stop(self):
if not self._disabled:
self._continue.set()
self._thread.join()

def __enter__(self):
self.start()
return self

def __exit__(self, *_):
self.stop()

0 comments on commit c93faa9

Please sign in to comment.