Skip to content

Commit

Permalink
fix: fixed issues with lost Context
Browse files Browse the repository at this point in the history
  • Loading branch information
adubovik committed Jan 20, 2025
1 parent f153e85 commit 950585d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion aidial_analytics_realtime/utils/concurrency.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import asyncio
import contextvars
import functools
from concurrent.futures import ThreadPoolExecutor
from typing import Callable, ParamSpec, TypeVar

Expand All @@ -12,4 +14,6 @@ async def run_in_cpu_tasks_executor(
func: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs
) -> _T:
loop = asyncio.get_event_loop()
return await loop.run_in_executor(cpu_task_executor, func, *args) # type: ignore
ctx = contextvars.copy_context()
func_call = functools.partial(ctx.run, func, *args, **kwargs)
return await loop.run_in_executor(cpu_task_executor, func_call) # type: ignore

0 comments on commit 950585d

Please sign in to comment.