Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Lazily create API ThreadPool #206

davidmezzetti2a4e47c7975c
diff --git a/src/python/txtai/api/base.py b/src/python/txtai/api/base.py
index 0bd02371..e99aa36b 100644
--- a/src/python/txtai/api/base.py
+++ b/src/python/txtai/api/base.py
@@ -62,7 +62,7 @@ class API:
self.lock = Lock()
# ThreadPool - runs scheduled workflows
- self.pool = ThreadPool()
+ self.pool = None
# Local embeddings index
if self.config.get("path") and Embeddings().exists(self.config["path"]):
@@ -146,6 +146,10 @@ class API:
# Schedule job if necessary
if schedule:
+ # Create pool if necessary
+ if not self.pool:
+ self.pool = ThreadPool()
+
self.pool.apply_async(self.workflows[workflow].schedule, kwds=schedule)
def resolve(self, task):