electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 917b7fa898479a80d19633279ced4d539819b8c2
parent 416b68705493a232818c28817129a126791147e8
Author: SomberNight <somber.night@protonmail.com>
Date:   Fri, 26 Oct 2018 22:43:33 +0200

network shutdown safety belts

Diffstat:
Melectrum/daemon.py | 1-
Melectrum/network.py | 33++++++++++++++++++---------------
Melectrum/util.py | 2+-
3 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/electrum/daemon.py b/electrum/daemon.py @@ -302,7 +302,6 @@ class Daemon(DaemonThread): if self.network: self.print_error("shutting down network") self.network.stop() - self.network.join() self.on_stop() def stop(self): diff --git a/electrum/network.py b/electrum/network.py @@ -836,29 +836,32 @@ class Network(PrintError): self._jobs.append(job) await self.main_taskgroup.spawn(job) + @log_exceptions async def _stop(self, full_shutdown=False): self.print_error("stopping network") try: await asyncio.wait_for(self.main_taskgroup.cancel_remaining(), timeout=2) - except asyncio.TimeoutError: pass - self.main_taskgroup = None - - assert self.interface is None - assert not self.interfaces - self.connecting.clear() - self.server_queue = None - self.trigger_callback('network_updated') - - if full_shutdown: - self._run_forever.set_result(1) + except (asyncio.TimeoutError, asyncio.CancelledError) as e: + self.print_error(f"exc during main_taskgroup cancellation: {repr(e)}") + try: + self.main_taskgroup = None + self.interface = None # type: Interface + self.interfaces = {} # type: Dict[str, Interface] + self.connecting.clear() + self.server_queue = None + if not full_shutdown: + self.trigger_callback('network_updated') + finally: + if full_shutdown: + self._run_forever.set_result(1) def stop(self): assert self._thread != threading.current_thread(), 'must not be called from network thread' fut = asyncio.run_coroutine_threadsafe(self._stop(full_shutdown=True), self.asyncio_loop) - fut.result() - - def join(self): - self._thread.join(1) + try: + fut.result(timeout=2) + except (asyncio.TimeoutError, asyncio.CancelledError): pass + self._thread.join(timeout=1) async def _ensure_there_is_a_main_interface(self): if self.is_connected(): diff --git a/electrum/util.py b/electrum/util.py @@ -882,7 +882,7 @@ def log_exceptions(func): raise except BaseException as e: print_ = self.print_error if hasattr(self, 'print_error') else print_error - print_("Exception in", func.__name__, ":", e.__class__.__name__, repr(e)) + print_("Exception in", func.__name__, ":", repr(e)) try: traceback.print_exc(file=sys.stderr) except BaseException as e2: