forked from LBRYCommunity/lbry-sdk
refactor BlobFile.close to be non async
This commit is contained in:
parent
f8dc0f298e
commit
0e972ec2ae
4 changed files with 7 additions and 5 deletions
|
@ -132,16 +132,18 @@ class BlobFile:
|
||||||
with open(self.file_path, 'rb') as handle:
|
with open(self.file_path, 'rb') as handle:
|
||||||
return await self.loop.sendfile(writer.transport, handle, count=self.get_length())
|
return await self.loop.sendfile(writer.transport, handle, count=self.get_length())
|
||||||
|
|
||||||
async def close(self):
|
def close(self):
|
||||||
while self.writers:
|
while self.writers:
|
||||||
self.writers.pop().finished.cancel()
|
self.writers.pop().finished.cancel()
|
||||||
|
|
||||||
async def delete(self):
|
async def delete(self):
|
||||||
await self.close()
|
self.close()
|
||||||
async with self.blob_write_lock:
|
async with self.blob_write_lock:
|
||||||
self.saved_verified_blob = False
|
self.saved_verified_blob = False
|
||||||
if os.path.isfile(self.file_path):
|
if os.path.isfile(self.file_path):
|
||||||
os.remove(self.file_path)
|
os.remove(self.file_path)
|
||||||
|
self.verified.clear()
|
||||||
|
self.finished_writing.clear()
|
||||||
|
|
||||||
def decrypt(self, key: bytes, iv: bytes) -> bytes:
|
def decrypt(self, key: bytes, iv: bytes) -> bytes:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -86,7 +86,7 @@ class BlobDownloader:
|
||||||
peer, task = self.active_connections.popitem()
|
peer, task = self.active_connections.popitem()
|
||||||
if task and not task.done():
|
if task and not task.done():
|
||||||
task.cancel()
|
task.cancel()
|
||||||
await blob.close()
|
blob.close()
|
||||||
log.debug("downloaded %s", blob_hash[:8])
|
log.debug("downloaded %s", blob_hash[:8])
|
||||||
return blob
|
return blob
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
|
|
|
@ -323,7 +323,7 @@ class BlobComponent(Component):
|
||||||
async def stop(self):
|
async def stop(self):
|
||||||
while self.blob_manager and self.blob_manager.blobs:
|
while self.blob_manager and self.blob_manager.blobs:
|
||||||
_, blob = self.blob_manager.blobs.popitem()
|
_, blob = self.blob_manager.blobs.popitem()
|
||||||
await blob.close()
|
blob.close()
|
||||||
|
|
||||||
async def get_status(self):
|
async def get_status(self):
|
||||||
count = 0
|
count = 0
|
||||||
|
|
|
@ -86,7 +86,7 @@ class StreamDescriptor:
|
||||||
writer = sd_blob.open_for_writing()
|
writer = sd_blob.open_for_writing()
|
||||||
writer.write(sd_data)
|
writer.write(sd_data)
|
||||||
await sd_blob.verified.wait()
|
await sd_blob.verified.wait()
|
||||||
await sd_blob.close()
|
sd_blob.close()
|
||||||
return sd_blob
|
return sd_blob
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Reference in a new issue