Skip to content

Commit

Permalink
Add context manager to Progress class
Browse files Browse the repository at this point in the history
  • Loading branch information
horta committed May 17, 2024
1 parent 5d45704 commit 3bb6404
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
7 changes: 7 additions & 0 deletions control/deciphonctl/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ def stop(self):
self._continue.set()
self._thread.join()
self._logger.stop()

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

def __exit__(self, *_):
self.stop()
16 changes: 8 additions & 8 deletions control/deciphonctl/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ def callback(self, message: str):
)
logger.info(f"scan parameters: {params}")
scan = Scan(params, db)
with scan:
bar = Progress("scan", scan, self._sched, x.job_id)
bar.start()
with scan, Progress("scan", scan, self._sched, x.job_id):
scan.dial(daemon.port)
for seq in x.seqs:
scan.add(Sequence(seq.id, seq.name, seq.data))
scan.run(snap)
bar.stop()
logger.info(
"Scan has finished successfully and "
f"results stored in '{snap.path}'."
)
if scan.interrupted():
raise InterruptedError("Scanner has been interrupted.")
snap.make_archive()
logger.info(
"Scan has finished successfully and "
f"results stored in '{snap.path}'."
)
self._sched.snap_post(x.id, snap.path)


Expand Down

0 comments on commit 3bb6404

Please sign in to comment.