attach subscriptions to on_connected and stop service before discarding the object

This commit is contained in:
Victor Shyba 2018-10-08 18:04:56 -03:00 committed by Lex Berezhny
parent d9c21ce37b
commit 9c4dfa7f84
2 changed files with 7 additions and 0 deletions

View file

@ -223,8 +223,13 @@ class BaseLedger(metaclass=LedgerRegistry):
self.headers.open() self.headers.open()
]) ])
first_connection = self.network.on_connected.first first_connection = self.network.on_connected.first
self.network.on_connected.listen(self.join_network)
self.network.start() self.network.start()
yield first_connection yield first_connection
@defer.inlineCallbacks
def join_network(self, *args):
log.info("Subscribing and updating accounts.")
yield self.update_headers() yield self.update_headers()
yield self.network.subscribe_headers() yield self.network.subscribe_headers()
yield self.update_accounts() yield self.update_accounts()

View file

@ -167,6 +167,8 @@ class BaseNetwork:
log.exception("Connecting to %s raised an exception:", connection_string) log.exception("Connecting to %s raised an exception:", connection_string)
finally: finally:
self.client = None self.client = None
if self.service is not None:
self.service.stopService()
if not self.running: if not self.running:
return return