From 98565eb67cab40e8214b8f96ed9f4fb42c39acad Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Tue, 9 Jun 2020 16:04:14 -0400 Subject: [PATCH] run read_raw_block in executor --- lbry/wallet/server/block_processor.py | 2 +- lbry/wallet/server/leveldb.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lbry/wallet/server/block_processor.py b/lbry/wallet/server/block_processor.py index 437b24f18..e2ecb69ce 100644 --- a/lbry/wallet/server/block_processor.py +++ b/lbry/wallet/server/block_processor.py @@ -251,7 +251,7 @@ class BlockProcessor: async def get_raw_blocks(last_height, hex_hashes): heights = range(last_height, last_height - len(hex_hashes), -1) try: - blocks = [self.db.read_raw_block(height) for height in heights] + blocks = [await self.db.read_raw_block(height) for height in heights] self.logger.info(f'read {len(blocks)} blocks from disk') return blocks except FileNotFoundError: diff --git a/lbry/wallet/server/leveldb.py b/lbry/wallet/server/leveldb.py index cdcbbe50a..fe048c9b4 100644 --- a/lbry/wallet/server/leveldb.py +++ b/lbry/wallet/server/leveldb.py @@ -479,11 +479,15 @@ class LevelDB: def raw_block_path(self, height): return os.path.join(self.env.db_dir, f'{self.raw_block_prefix()}{height:d}') - def read_raw_block(self, height): + async def read_raw_block(self, height): """Returns a raw block read from disk. Raises FileNotFoundError if the block isn't on-disk.""" - with util.open_file(self.raw_block_path(height)) as f: - return f.read(-1) + + def read(): + with util.open_file(self.raw_block_path(height)) as f: + return f.read(-1) + + return await asyncio.get_event_loop().run_in_executor(self.executor, read) def write_raw_block(self, block, height): """Write a raw block to disk."""