mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-17 09:21:17 +02:00
fix the uncontrollable zipfile closing function
This commit is contained in:
parent
36aa321ade
commit
a4eb7f3b5f
@ -139,6 +139,7 @@ class Downloader(Singleton):
|
|||||||
except EnvironmentError as e:
|
except EnvironmentError as e:
|
||||||
logger.critical(str(e))
|
logger.critical(str(e))
|
||||||
self.folder:str = folder
|
self.folder:str = folder
|
||||||
|
self.close = lambda: None # Only available in class CompressedDownloader
|
||||||
|
|
||||||
def start_download(self, queue, folder='') -> bool:
|
def start_download(self, queue, folder='') -> bool:
|
||||||
if not isinstance(folder, (str,)):
|
if not isinstance(folder, (str,)):
|
||||||
@ -164,6 +165,8 @@ class Downloader(Singleton):
|
|||||||
# Prevent coroutines infection
|
# Prevent coroutines infection
|
||||||
asyncio.run(self.fiber(coroutines))
|
asyncio.run(self.fiber(coroutines))
|
||||||
|
|
||||||
|
self.close()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
class CompressedDownloader(Downloader):
|
class CompressedDownloader(Downloader):
|
||||||
@ -171,6 +174,7 @@ class CompressedDownloader(Downloader):
|
|||||||
filename = f'{folder}.zip'
|
filename = f'{folder}.zip'
|
||||||
print(filename)
|
print(filename)
|
||||||
self.zipfile = zipfile.ZipFile(filename,'w')
|
self.zipfile = zipfile.ZipFile(filename,'w')
|
||||||
|
self.close = lambda: self.zipfile.close()
|
||||||
|
|
||||||
async def save(self, filename, response) -> bool:
|
async def save(self, filename, response) -> bool:
|
||||||
if response is None:
|
if response is None:
|
||||||
@ -189,6 +193,3 @@ class CompressedDownloader(Downloader):
|
|||||||
image_data.seek(0)
|
image_data.seek(0)
|
||||||
self.zipfile.writestr(filename, image_data.read())
|
self.zipfile.writestr(filename, image_data.read())
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
self.zipfile.close()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user