From 7667c060bd81e3084d6dd1c48fcd5cb6dae80257 Mon Sep 17 00:00:00 2001 From: Hans Kallekleiv <16436291+HansKallekleiv@users.noreply.github.com> Date: Tue, 14 Nov 2023 11:15:42 +0100 Subject: [PATCH] sync --- .../backend/primary/routers/surface/router.py | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/backend/src/backend/primary/routers/surface/router.py b/backend/src/backend/primary/routers/surface/router.py index 872498202..1b343d621 100644 --- a/backend/src/backend/primary/routers/surface/router.py +++ b/backend/src/backend/primary/routers/surface/router.py @@ -1,6 +1,6 @@ import logging from typing import List, Union, Optional - +import asyncio from fastapi import APIRouter, Depends, HTTPException, Query, Response from src.services.sumo_access.surface_access import SurfaceAccess @@ -184,6 +184,23 @@ async def get_realization_surface_data_as_png( return surf_data_response +class AsyncRange: + def __init__(self, start, end): + self.current = start + self.end = end + + def __aiter__(self): + return self + + async def __anext__(self): + if self.current < self.end: + number = self.current + self.current += 1 + return number + else: + raise StopAsyncIteration + + @router.get("/statistical_surface_data_as_png/") async def get_statistical_surface_data_as_png( response: Response, @@ -210,13 +227,21 @@ async def get_statistical_surface_data_as_png( ) if service_stat_func_to_compute is None: raise HTTPException(status_code=404, detail="Invalid statistic requested") - - xtgeo_surf = await access.get_statistical_surface_data_async( - statistic_function=service_stat_func_to_compute, - name=name, - attribute=attribute, - time_or_interval_str=time_or_interval, - ) + xtg_arr = [] + print("before loop", flush=True) + for i in range(0, 100): + print(i, flush=True) + xtg_arr.append( + access.get_statistical_surface_data_async( + statistic_function=service_stat_func_to_compute, + name=name, + attribute=attribute, + time_or_interval_str=time_or_interval, + ) + ) + print("before await", flush=True) + await asyncio.gather(*xtg_arr) + print("after await", flush=True) perf_metrics.record_lap("sumo-calc") if not xtgeo_surf: