Browse Source

Plugins: make Plugins.stop() faster

Plugins.stop() is now part of the normal shutdown flow (since 90f39bce88),
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.
master
SomberNight 2 years ago
parent
commit
6a9e532ff1
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 2
      electrum/plugin.py
  2. 3
      electrum/util.py

2
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()

3
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:

Loading…
Cancel
Save