improvement: suggestions are now retrieved asynchronously

This commit is contained in:
Vinicius Moreira
2019-08-06 19:08:34 -03:00
parent 2d8c9bdf20
commit 1565d418e9
2 changed files with 19 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
import time
from abc import ABC, abstractmethod
from argparse import Namespace
from threading import Thread
from typing import List, Dict
from fpakman.core.disk import DiskCacheLoader, DiskCacheLoaderFactory
@@ -290,10 +291,22 @@ class GenericApplicationManager(ApplicationManager):
return warnings
def _fill_suggestions(self, suggestions: list, man: ApplicationManager):
if self._is_enabled(man):
suggestions.extend(man.list_suggestions(6))
def list_suggestions(self, limit: int) -> List[Application]:
ti = time.time()
if self.managers:
suggestions = []
suggestions, threads = [], []
for man in self.managers:
if self._is_enabled(man):
suggestions.extend(man.list_suggestions(6))
t = Thread(target=self._fill_suggestions, args=(suggestions, man))
t.start()
threads.append(t)
for t in threads:
t.join()
tf = time.time() - ti
print(tf)
return suggestions