refactor BlobFile.close to be non async

This commit is contained in:
Jack Robison 2019-02-06 09:20:21 -05:00
parent f8dc0f298e
commit 0e972ec2ae
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
4 changed files with 7 additions and 5 deletions

View file

@ -132,16 +132,18 @@ class BlobFile:
with open(self.file_path, 'rb') as handle:
return await self.loop.sendfile(writer.transport, handle, count=self.get_length())
async def close(self):
def close(self):
while self.writers:
self.writers.pop().finished.cancel()
async def delete(self):
await self.close()
self.close()
async with self.blob_write_lock:
self.saved_verified_blob = False
if os.path.isfile(self.file_path):
os.remove(self.file_path)
self.verified.clear()
self.finished_writing.clear()
def decrypt(self, key: bytes, iv: bytes) -> bytes:
"""

View file

@ -86,7 +86,7 @@ class BlobDownloader:
peer, task = self.active_connections.popitem()
if task and not task.done():
task.cancel()
await blob.close()
blob.close()
log.debug("downloaded %s", blob_hash[:8])
return blob
except asyncio.CancelledError:

View file

@ -323,7 +323,7 @@ class BlobComponent(Component):
async def stop(self):
while self.blob_manager and self.blob_manager.blobs:
_, blob = self.blob_manager.blobs.popitem()
await blob.close()
blob.close()
async def get_status(self):
count = 0

View file

@ -86,7 +86,7 @@ class StreamDescriptor:
writer = sd_blob.open_for_writing()
writer.write(sd_data)
await sd_blob.verified.wait()
await sd_blob.close()
sd_blob.close()
return sd_blob
@classmethod