def get_friends(cache: DbfilenameShelf = None, name: str = SHLOMO): if cache is not None: friends = cache.get(name) if friends is not None: return cache[name] response = get_first_request(name) first_page_singers = response[0] parallel_searcher = response[1] pages_range = response[2] if not pages_range: # only 1 page friends = first_page_singers else: with TPool(INNER_MAX_WORKERS) as pool: next_pages_singers = pool.map(parallel_searcher, pages_range) friends = first_page_singers.union(*next_pages_singers) if cache is not None: cache[name] = friends cache.sync() return friends
def sync(self): # noinspection PyUnresolvedReferences self._debug(f'Synchronizing...', header=f'Cache "{self.filename}"') DbfilenameShelf.sync(self) # noinspection PyUnresolvedReferences self._debug('Synchronized', header=f'Cache "{self.filename}"')