From d68ca65e41d2aa76fafbd9031df269739dc0a120 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Fri, 29 Sep 2017 14:29:35 -0400 Subject: [PATCH] warn if reader is garbage collected but not closed, do the same for writer --- lbrynet/blob/reader.py | 6 +++++- lbrynet/blob/writer.py | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lbrynet/blob/reader.py b/lbrynet/blob/reader.py index dd248c8fd..4d1f51dff 100644 --- a/lbrynet/blob/reader.py +++ b/lbrynet/blob/reader.py @@ -40,11 +40,15 @@ class HashBlobReader(object): read(size) and close() """ def __init__(self, file_path, finished_cb): + self.file_path = file_path self.finished_cb = finished_cb self.finished_cb_d = None - self.read_handle = open(file_path, 'rb') + self.read_handle = open(self.file_path, 'rb') def __del__(self): + if self.finished_cb_d is None: + log.warn("Garbage collection was called, but reader for %s was not closed yet", + self.file_path) self.close() def read(self, size=-1): diff --git a/lbrynet/blob/writer.py b/lbrynet/blob/writer.py index a95430386..dc4d3d77a 100644 --- a/lbrynet/blob/writer.py +++ b/lbrynet/blob/writer.py @@ -16,6 +16,11 @@ class HashBlobWriter(object): self._hashsum = get_lbry_hash_obj() self.len_so_far = 0 + def __del__(self): + if self.finished_cb_d is None: + log.warn("Garbage collection was called, but writer was not closed yet") + self.close() + @property def blob_hash(self): return self._hashsum.hexdigest()