From cbd9c2ccf10ba465e307708608be5c0cf9ece946 Mon Sep 17 00:00:00 2001 From: Neeraj Kashyap Date: Thu, 29 Jul 2021 11:41:37 -0700 Subject: [PATCH] Wait for crawling futures to return --- crawlers/moonstreamcrawlers/ethereum.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crawlers/moonstreamcrawlers/ethereum.py b/crawlers/moonstreamcrawlers/ethereum.py index a2e51999..f35b4827 100644 --- a/crawlers/moonstreamcrawlers/ethereum.py +++ b/crawlers/moonstreamcrawlers/ethereum.py @@ -1,4 +1,4 @@ -from concurrent.futures import ProcessPoolExecutor +from concurrent.futures import Future, ProcessPoolExecutor, wait from typing import List, Optional from web3 import Web3 @@ -129,12 +129,17 @@ def crawl_blocks_executor( for i, block_number in enumerate(block_numbers_list): worker_job_lists[i % MOONSTREAM_CRAWL_WORKERS].append(block_number) + results: List[Future] = [] + with ProcessPoolExecutor(max_workers=MOONSTREAM_CRAWL_WORKERS) as executor: for worker in worker_indices: if verbose: print(f"Spawned process for {len(worker_job_lists[worker])} blocks") - executor.submit( + result = executor.submit( crawl_blocks, worker_job_lists[worker], with_transactions, ) + results.append(result) + + wait(results)