diff options
author | RĂ©mi Duraffort <remi.duraffort@linaro.org> | 2018-07-20 13:12:44 +0200 |
---|---|---|
committer | Neil Williams <neil.williams@linaro.org> | 2018-07-23 16:20:01 +0000 |
commit | fc083df5c7823c40c3546645c0e780731093e2f0 (patch) | |
tree | 4deab1ea8a6bb8cac2085c682ff2d959758ec20f | |
parent | 861140e51057943b54a7b707743d906e01f9b7cc (diff) |
Use contextlib.suppress when applicable
Change-Id: Ib4f3c0bd002c95e4a5456c5e45b5f7436907662e
-rwxr-xr-x | lava/dispatcher/lava-slave | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/lava/dispatcher/lava-slave b/lava/dispatcher/lava-slave index 6f2cc01ae..89c262723 100755 --- a/lava/dispatcher/lava-slave +++ b/lava/dispatcher/lava-slave @@ -220,10 +220,9 @@ class Job(object): mkdir(self.base_dir) def errors(self): - try: + with contextlib.suppress(IOError): return open(os.path.join(self.base_dir, "stderr"), 'r').read() - except IOError: - return '' + return '' def description(self): try: @@ -248,11 +247,10 @@ class Job(object): os.kill(self.pid, signal.SIGTERM) def is_running(self): - try: + with contextlib.suppress(IOError): with open("/proc/%d/cmdline" % self.pid, "r") as fd: return "lava-run" in fd.read() - except IOError: - return False + return False def send_end(self, sock): errors = self.errors() @@ -282,13 +280,12 @@ class JobsDB(object): """ When pid is 0, the pid is unknown """ - try: + with contextlib.suppress(sqlite3.Error): self.conn.execute("INSERT INTO jobs VALUES(?, ?, ?, ?)", (str(job_id), str(pid), str(status), str(int(time.time())))) self.conn.commit() return self.get(job_id) - except sqlite3.Error: - return None + return None def get(self, job_id): row = self.conn.execute("SELECT * FROM jobs WHERE id=?", (str(job_id), )).fetchone() @@ -296,13 +293,12 @@ class JobsDB(object): def update(self, job_id, status): - try: + with contextlib.suppress(sqlite3.Error): self.conn.execute("UPDATE jobs SET status=?, last_update=? WHERE id=?", (str(status), str(int(time.time())), str(job_id))) self.conn.commit() return self.get(job_id) - except sqlite3.Error: - return None + return None def delete(self, job_id): with contextlib.suppress(sqlite3.Error): |