1
0

run_electrum: have daemon manage Plugins object, and call Plugins.stop

Plugins.stop was never called, so the Plugins thread only stopped
because of the is_running() check in run(), which triggers too late:
the Plugins thread was stopping after the main thread stopped.

E.g. playing around in the qt wizard with wallet creation for a Trezor,
and closing the wizard (only window):
``` 24.85 | E | p/plugin.Plugins |
Traceback (most recent call last):
  File "/home/user/wspace/electrum/electrum/util.py", line 386, in run_jobs
    job.run()
  File "/home/user/wspace/electrum/electrum/plugin.py", line 430, in run
    client.timeout(cutoff)
  File "/home/user/wspace/electrum/electrum/plugin.py", line 363, in wrapper
    return run_in_hwd_thread(partial(func, *args, **kwargs))
  File "/home/user/wspace/electrum/electrum/plugin.py", line 355, in run_in_hwd_thread
    fut = _hwd_comms_executor.submit(func)
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 167, in submit
    raise RuntimeError('cannot schedule new futures after shutdown')
RuntimeError: cannot schedule new futures after shutdown
```
This commit is contained in:
SomberNight
2023-08-24 16:56:23 +00:00
parent c12d9b14da
commit 90f39bce88
3 changed files with 25 additions and 8 deletions

View File

@@ -370,7 +370,8 @@ class DaemonThread(threading.Thread, Logger):
self.running_lock = threading.Lock()
self.job_lock = threading.Lock()
self.jobs = []
self.stopped_event = threading.Event() # set when fully stopped
self.stopped_event = threading.Event() # set when fully stopped
self.stopped_event_async = asyncio.Event() # set when fully stopped
def add_jobs(self, jobs):
with self.job_lock:
@@ -412,6 +413,8 @@ class DaemonThread(threading.Thread, Logger):
self.logger.info("jnius detach")
self.logger.info("stopped")
self.stopped_event.set()
loop = get_asyncio_loop()
loop.call_soon_threadsafe(self.stopped_event_async.set)
def print_stderr(*args):