mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-20 02:41:19 +02:00
singleton pool
This commit is contained in:
parent
349e21193b
commit
8dc7a1f40b
@ -27,6 +27,17 @@ class NHentaiImageNotExistException(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Pool(Singleton):
|
||||||
|
pool = None
|
||||||
|
|
||||||
|
def __init__(self, size, init):
|
||||||
|
if self.pool is None:
|
||||||
|
if os.getenv('DEBUG'):
|
||||||
|
logger.info('Process pool created')
|
||||||
|
|
||||||
|
self.pool = mp.Pool(size, initializer=init)
|
||||||
|
|
||||||
|
|
||||||
class Downloader(Singleton):
|
class Downloader(Singleton):
|
||||||
|
|
||||||
def __init__(self, path='', thread=1, timeout=30, delay=0):
|
def __init__(self, path='', thread=1, timeout=30, delay=0):
|
||||||
@ -135,7 +146,7 @@ class Downloader(Singleton):
|
|||||||
|
|
||||||
queue = [(self, url, folder) for url in queue]
|
queue = [(self, url, folder) for url in queue]
|
||||||
|
|
||||||
pool = mp.Pool(self.thread_count, init_worker)
|
pool = Pool(self.thread_count, init_worker).pool
|
||||||
for item in queue:
|
for item in queue:
|
||||||
pool.apply_async(download_wrapper, args=item, callback=self._download_callback)
|
pool.apply_async(download_wrapper, args=item, callback=self._download_callback)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user