1
0

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.
This commit is contained in:
SomberNight
2023-08-24 18:27:34 +00:00
parent 392f6d8e30
commit 6a9e532ff1
2 changed files with 4 additions and 1 deletions

View File

@@ -209,7 +209,7 @@ class Plugins(DaemonThread):
def run(self): def run(self):
while self.is_running(): 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.run_jobs()
self.on_stop() self.on_stop()

View File

@@ -372,6 +372,7 @@ class DaemonThread(threading.Thread, Logger):
self.jobs = [] 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 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): def add_jobs(self, jobs):
with self.job_lock: with self.job_lock:
@@ -405,6 +406,8 @@ class DaemonThread(threading.Thread, Logger):
def stop(self): def stop(self):
with self.running_lock: with self.running_lock:
self.running = False self.running = False
self.wake_up_event.set()
self.wake_up_event.clear()
def on_stop(self): def on_stop(self):
if 'ANDROID_DATA' in os.environ: if 'ANDROID_DATA' in os.environ: