def get_parallel_dividends()

in src/backend/domain/data_providers/default.py [0:0]


    def get_parallel_dividends(self, symbols: List[str], start_date: str, end_date: str) -> Tuple[Dict[str, Any], Optional[str]]:
        symbol_to_dividends = {}
        error_message = None

        max_workers = os.cpu_count() * 2 - 1
        with ThreadPoolExecutor(max_workers=max_workers) as executor:
            future_to_symbol = {executor.submit(self.get_dividends, symbol, start_date, end_date): symbol for symbol in symbols}

            if self.progress_callback is not None:
                for future in future_to_symbol:
                    future.add_done_callback(self.progress_callback)

            for future in as_completed(future_to_symbol):
                symbol = future_to_symbol[future]
                symbol_data, error_message = future.result()

                if symbol_data is not None:
                    symbol_to_dividends[symbol] = symbol_data
                if error_message is not None:
                    for future in future_to_symbol.keys():
                        future.cancel()
                    executor.shutdown(wait=False)
                    break

        return symbol_to_dividends, error_message