From 238b9e02851b86923178236e063b27f6fddbd267 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Sat, 3 Dec 2016 23:05:05 +0900 Subject: [PATCH] Process blocks in the executor This should eliminate latency when new blocks come in and prevent sessions being dropped whilst they are processed. --- server/block_processor.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/server/block_processor.py b/server/block_processor.py index fbe2c57..0ad73a9 100644 --- a/server/block_processor.py +++ b/server/block_processor.py @@ -201,6 +201,7 @@ class BlockProcessor(server.db.DB): self.first_caught_up() self.flush(True) + self.logger.info('shut down complete') def shutdown(self): '''Call to shut down the block processor.''' @@ -213,11 +214,16 @@ class BlockProcessor(server.db.DB): if self.height == -1: blocks[0] = blocks[0][:self.coin.HEADER_LEN] + bytes(1) - touched = set() - try: + def do_it(): for block in blocks: + if self._shutdown: + break self.advance_block(block, touched) - await asyncio.sleep(0) # Yield + + touched = set() + loop = asyncio.get_event_loop() + try: + await loop.run_in_executor(None, do_it) except ChainReorg: await self.handle_chain_reorg(touched)