diff --git a/src/sakia/core/account.py b/src/sakia/core/account.py index 1dccb25117dec6f49c739a51124dcae1482acd0a..3d2bf4d9b4aa54d9c408533c7e45d10c84d92df5 100644 --- a/src/sakia/core/account.py +++ b/src/sakia/core/account.py @@ -574,14 +574,14 @@ class Account(QObject): for c in self.communities: c.start_coroutines() - async def stop_coroutines(self): + async def stop_coroutines(self, closing=False): logging.debug("Stop communities coroutines") for c in self.communities: - await c.stop_coroutines() + await c.stop_coroutines(closing) logging.debug("Stop wallets coroutines") for w in self.wallets: - w.stop_coroutines() + w.stop_coroutines(closing) logging.debug("Account coroutines stopped") def jsonify(self): diff --git a/src/sakia/core/app.py b/src/sakia/core/app.py index b8ee0fa02e1befbe63f83c4878a0ef1a9f8d0fc2..90afa4158379a908b5c67fb282387fa835ad53e9 100644 --- a/src/sakia/core/app.py +++ b/src/sakia/core/app.py @@ -197,14 +197,14 @@ class Application(QObject): self._current_account.start_coroutines() self.account_changed.emit() - async def stop_current_account(self): + async def stop_current_account(self, closing=False): """ Save the account to the cache and stop the coroutines """ self.save_cache(self._current_account) self.save_notifications(self._current_account) - await self._current_account.stop_coroutines() + await self._current_account.stop_coroutines(closing) def load(self): """ @@ -510,7 +510,7 @@ class Application(QObject): async def stop(self): if self._current_account: - await self.stop_current_account() + await self.stop_current_account(closing=True) await asyncio.sleep(0) self.save_registries() diff --git a/src/sakia/core/community.py b/src/sakia/core/community.py index 2b3b1a39e9d86ccfc41a200e59ab99d900adda31..23b860c18a18af819ba2b1a8be7b93cf593a1b36 100644 --- a/src/sakia/core/community.py +++ b/src/sakia/core/community.py @@ -321,8 +321,8 @@ class Community(QObject): def start_coroutines(self): self.network.start_coroutines() - async def stop_coroutines(self): - await self.network.stop_coroutines() + async def stop_coroutines(self, closing=False): + await self.network.stop_coroutines(closing) def rollback_cache(self): self._bma_access.rollback() diff --git a/src/sakia/core/net/network.py b/src/sakia/core/net/network.py index 3fe0ae244842d3aad9ea21d0a403b0e25dbf5477..30d7cb9436887f0de919cf02c0d83a0e48a64570 100644 --- a/src/sakia/core/net/network.py +++ b/src/sakia/core/net/network.py @@ -141,7 +141,7 @@ class Network(QObject): """ asyncio.ensure_future(self.discover_network()) - async def stop_coroutines(self): + async def stop_coroutines(self, closing=False): """ Stop network nodes crawling. """ @@ -150,10 +150,12 @@ class Network(QObject): logging.debug("Start closing") for node in self.nodes: close_tasks.append(asyncio.ensure_future(node.close_ws())) + logging.debug("Closing {0} websockets".format(len(close_tasks))) if len(close_tasks) > 0: await asyncio.wait(close_tasks, timeout=15) - logging.debug("Closing client session") - await self._client_session.close() + if closing: + logging.debug("Closing client session") + await self._client_session.close() logging.debug("Closed") @property diff --git a/src/sakia/core/txhistory.py b/src/sakia/core/txhistory.py index ec9976bb31bcbc96b1c7e7ea8421c4dfe0e1d3e0..ecfa725f85f88c658c9766c32baf6bcb80e0eb3c 100644 --- a/src/sakia/core/txhistory.py +++ b/src/sakia/core/txhistory.py @@ -86,7 +86,7 @@ class TxHistory(): def dividends(self): return self._dividends.copy() - def stop_coroutines(self): + def stop_coroutines(self, closing=False): self._stop_coroutines = True async def _get_block_doc(self, community, number): diff --git a/src/sakia/core/wallet.py b/src/sakia/core/wallet.py index 842586ea388e40025cf0a55fad8f8b294e970982..515240758061edaff25db4c1a4be7be4a259acb9 100644 --- a/src/sakia/core/wallet.py +++ b/src/sakia/core/wallet.py @@ -373,9 +373,9 @@ class Wallet(QObject): else: return [] - def stop_coroutines(self): + def stop_coroutines(self, closing=False): for c in self.caches.values(): - c.stop_coroutines() + c.stop_coroutines(closing) def jsonify(self): """