Browse Source

commands: make stop() CLI cmd wait for daemon to stop

master
SomberNight 5 years ago
parent
commit
5dfe1d1b6c
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 3
      electrum/commands.py
  2. 8
      electrum/daemon.py

3
electrum/commands.py

@ -209,7 +209,8 @@ class Commands:
@command('n')
async def stop(self):
"""Stop daemon"""
self.daemon.stop()
# TODO it would be nice if this could stop the GUI too
await self.daemon.stop()
return "Daemon stopped"
@command('n')

8
electrum/daemon.py

@ -455,6 +455,7 @@ class Daemon(Logger):
if self.config.get('use_gossip', False):
self.network.start_gossip()
self.stopped_event = asyncio.Event()
self.taskgroup = TaskGroup()
asyncio.run_coroutine_threadsafe(self._run(jobs=daemon_jobs), self.asyncio_loop)
@ -542,16 +543,17 @@ class Daemon(Logger):
with self.running_lock:
return self.running and not self.taskgroup.closed()
def stop(self):
async def stop(self):
with self.running_lock:
self.running = False
await self.stopped_event.wait()
def on_stop(self):
try:
self.logger.info("on_stop() entered. initiating shutdown")
if self.gui_object:
self.gui_object.stop()
@log_exceptions
async def stop_async():
self.logger.info("stopping all wallets")
async with TaskGroup() as group:
@ -566,9 +568,11 @@ class Daemon(Logger):
fut = asyncio.run_coroutine_threadsafe(stop_async(), self.asyncio_loop)
fut.result()
finally:
self.logger.info("removing lockfile")
remove_lockfile(get_lockfile(self.config))
self.logger.info("stopped")
self.asyncio_loop.call_soon_threadsafe(self.stopped_event.set)
def run_gui(self, config, plugins):
threading.current_thread().setName('GUI')

Loading…
Cancel
Save