From 574bc768298940a0275b6b969110cba64fa5b180 Mon Sep 17 00:00:00 2001 From: inso <insomniak.fr@gmaiL.com> Date: Tue, 3 May 2016 08:05:58 +0200 Subject: [PATCH] Fix bug #412 --- src/sakia/core/account.py | 6 +++--- src/sakia/core/app.py | 6 +++--- src/sakia/core/community.py | 4 ++-- src/sakia/core/net/network.py | 8 +++++--- src/sakia/core/txhistory.py | 2 +- src/sakia/core/wallet.py | 4 ++-- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/sakia/core/account.py b/src/sakia/core/account.py index 1dccb251..3d2bf4d9 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 b8ee0fa0..90afa415 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 2b3b1a39..23b860c1 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 3fe0ae24..30d7cb94 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 ec9976bb..ecfa725f 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 842586ea..51524075 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): """ -- GitLab