diff --git a/CHANGELOG.md b/CHANGELOG.md index 735d135f..9a39c7e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] ### Fixed +- Regression in v0.5.2 where plotting processes that lack log files caused a traceback. + ([#926](https://github.com/ericaltendorf/plotman/pull/926)) ### Added ## [0.5.2] - 2021-09-12 diff --git a/src/plotman/job.py b/src/plotman/job.py index 198ff674..1dc1444f 100644 --- a/src/plotman/job.py +++ b/src/plotman/job.py @@ -4,6 +4,7 @@ import glob import time from datetime import datetime +import sys import typing import attr @@ -105,7 +106,7 @@ class Job: plotter: "plotman.plotters.Plotter" - logfile: str = "" + logfile: typing.Optional[str] = None job_id: int = 0 proc: psutil.Process @@ -189,10 +190,11 @@ def get_running_jobs( plotter=plotter, logroot=logroot, ) - # TODO: stop reloading every time... - with open(job.logfile, "rb") as f: - r = f.read() - job.plotter.update(chunk=r) + if job.logfile is not None: + # TODO: stop reloading every time... + with open(job.logfile, "rb") as f: + r = f.read() + job.plotter.update(chunk=r) jobs.append(job) return jobs @@ -254,6 +256,10 @@ def status_str_long(self) -> str: # ) def print_logs(self, follow: bool = False) -> None: + if self.logfile is None: + print("no log file available for this plotting process", file=sys.stderr) + return + with open(self.logfile, "r") as f: if follow: line = ""