warn if reader is garbage collected but not closed, do the same for writer
This commit is contained in:
parent
23108585f4
commit
d68ca65e41
2 changed files with 10 additions and 1 deletions
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue