From f280586e6878bd94e707fab6cd37660d5c71b08f Mon Sep 17 00:00:00 2001 From: rkuo-danswer Date: Thu, 1 Aug 2024 17:06:35 -0700 Subject: [PATCH] pass function to Process correctly instead of running it inline (#2018) * pass function to Process correctly instead of running it inline * mypy fixes and pass back return result (even tho we don't use it right now) --- backend/danswer/background/indexing/job_client.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/danswer/background/indexing/job_client.py b/backend/danswer/background/indexing/job_client.py index 72919d690a46..68d706895fdf 100644 --- a/backend/danswer/background/indexing/job_client.py +++ b/backend/danswer/background/indexing/job_client.py @@ -41,6 +41,12 @@ def _initializer( return func(*args, **kwargs) +def _run_in_process( + func: Callable, args: list | tuple, kwargs: dict[str, Any] | None = None +) -> None: + _initializer(func, args, kwargs) + + @dataclass class SimpleJob: """Drop in replacement for `dask.distributed.Future`""" @@ -113,7 +119,7 @@ class SimpleJobClient: job_id = self.job_id_counter self.job_id_counter += 1 - process = Process(target=_initializer(func=func, args=args), daemon=True) + process = Process(target=_run_in_process, args=(func, args), daemon=True) job = SimpleJob(id=job_id, process=process) process.start()