From 196aa24b8b64917f077051acbaf087abf872d5c7 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Wed, 13 Sep 2017 12:58:11 -0400 Subject: [PATCH] add HashBlobWriter.close_handle() function to just close the write handle --- lbrynet/core/HashBlob.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lbrynet/core/HashBlob.py b/lbrynet/core/HashBlob.py index 053362118..452e4ce7a 100644 --- a/lbrynet/core/HashBlob.py +++ b/lbrynet/core/HashBlob.py @@ -71,13 +71,17 @@ class HashBlobWriter(object): if self.len_so_far == self.length_getter(): self.finished_cb(self) - def close(self, reason=None): - if reason is None: - reason = Failure(DownloadCanceledError()) + def close_handle(self): if self.write_handle is not None: self.write_handle.close() self.write_handle = None + def close(self, reason=None): + # we've already closed, so do nothing + if self.write_handle is None: + return + if reason is None: + reason = Failure(DownloadCanceledError()) self.finished_cb(self, reason) @@ -180,7 +184,7 @@ class HashBlob(object): else: errback_finished_deferred(err) d = defer.succeed(True) - + d.addBoth(lambda _: writer.close_handle()) return d def open_for_writing(self, peer):