From 6a9e532ff1b20de57b0e1beead5d2fc54e87443b Mon Sep 17 00:00:00 2001 From: SomberNight Date: Thu, 24 Aug 2023 18:27:34 +0000 Subject: [PATCH] Plugins: make Plugins.stop() faster Plugins.stop() is now part of the normal shutdown flow (since 90f39bce88dc3cb7b097a9bfc57b150abb936b3e), so this shaves up to 100 ms off that (avg: 50 ms). It is also waited on in around ~60 unit tests: this saves 3 sec. --- electrum/plugin.py | 2 +- electrum/util.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/electrum/plugin.py b/electrum/plugin.py index 8879e15a7..a2f7bff8f 100644 --- a/electrum/plugin.py +++ b/electrum/plugin.py @@ -209,7 +209,7 @@ class Plugins(DaemonThread): def run(self): while self.is_running(): - time.sleep(0.1) + self.wake_up_event.wait(0.1) # time.sleep(0.1) OR event self.run_jobs() self.on_stop() diff --git a/electrum/util.py b/electrum/util.py index cbf8a6a30..678aa9d9e 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -372,6 +372,7 @@ class DaemonThread(threading.Thread, Logger): self.jobs = [] self.stopped_event = threading.Event() # set when fully stopped self.stopped_event_async = asyncio.Event() # set when fully stopped + self.wake_up_event = threading.Event() # for perf optimisation of polling in run() def add_jobs(self, jobs): with self.job_lock: @@ -405,6 +406,8 @@ class DaemonThread(threading.Thread, Logger): def stop(self): with self.running_lock: self.running = False + self.wake_up_event.set() + self.wake_up_event.clear() def on_stop(self): if 'ANDROID_DATA' in os.environ: