Browse Source

Slightly cleaner semaphore fix

master
Neil Booth 8 years ago
parent
commit
67908b3541
  1. 9
      server/block_processor.py

9
server/block_processor.py

@ -1,4 +1,4 @@
# Copyright (c) 2016, Neil Booth # Copyright (c) 2016-2017, Neil Booth
# #
# All rights reserved. # All rights reserved.
# #
@ -88,9 +88,8 @@ class Prefetcher(LoggedClass):
while True: while True:
try: try:
with await self.semaphore: # Sleep a while if there is nothing to prefetch
fetched = await self._prefetch_blocks(caught_up_event.is_set()) if not await self._prefetch_blocks(caught_up_event.is_set()):
if not fetched:
await asyncio.sleep(5) await asyncio.sleep(5)
await self.refill_event.wait() await self.refill_event.wait()
except DaemonError as e: except DaemonError as e:
@ -106,6 +105,7 @@ class Prefetcher(LoggedClass):
sleep for a period of time before returning. sleep for a period of time before returning.
''' '''
daemon_height = await self.daemon.height(mempool) daemon_height = await self.daemon.height(mempool)
with await self.semaphore:
while self.cache_size < self.min_cache_size: while self.cache_size < self.min_cache_size:
# Try and catch up all blocks but limit to room in cache. # Try and catch up all blocks but limit to room in cache.
# Constrain fetch count to between 0 and 2500 regardless. # Constrain fetch count to between 0 and 2500 regardless.
@ -123,6 +123,7 @@ class Prefetcher(LoggedClass):
self.logger.info('new block height {:,d} hash {}' self.logger.info('new block height {:,d} hash {}'
.format(first + count-1, hex_hashes[-1])) .format(first + count-1, hex_hashes[-1]))
blocks = await self.daemon.raw_blocks(hex_hashes) blocks = await self.daemon.raw_blocks(hex_hashes)
assert count == len(blocks) assert count == len(blocks)
# Strip the unspendable genesis coinbase # Strip the unspendable genesis coinbase

Loading…
Cancel
Save