From 8eeb395a73a9a3c18b9c7659eedd5cf3927257d2 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 27 Jul 2024 19:03:29 -0300 Subject: Fix: plugin: opener: searcher: use asyncio instead of threading, and fix the background process --- packages/finder/plugin/searcher/file/name.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'packages') diff --git a/packages/finder/plugin/searcher/file/name.py b/packages/finder/plugin/searcher/file/name.py index caf2a63..0a9567c 100644 --- a/packages/finder/plugin/searcher/file/name.py +++ b/packages/finder/plugin/searcher/file/name.py @@ -21,8 +21,8 @@ import os import re import json +import asyncio -from threading import Thread from platformdirs import user_cache_dir class FinderPluginFileNameSearcher(): @@ -49,7 +49,8 @@ class FinderPluginFileNameSearcher(): self.items = json.load(f) # Then update the folder list in the background - walker = Thread(target=self.walker, name='Walker for ' + self.path) + async with asyncio.TaskGroup() as tg: + walker = tg.create_task(self.walker()) return self.items @@ -72,9 +73,10 @@ class FinderPluginFileNameSearcher(): def has_cache(self): pass - def walker(self): + async def walker(self): ignore_folders = [ '.git', '__pycache__' ] ignore_files = [ '.gitignore', '.gitattributes', '.gitmodules' ] + items = [] for parent, dirs, files in os.walk(self.path): # Do not traverse some folders @@ -101,4 +103,6 @@ class FinderPluginFileNameSearcher(): if file.startswith('.'): continue - self.items.append(os.path.join(parent, file)) + items.append(os.path.join(parent, file)) + + self.items = items -- cgit v1.2.3