1

I have a functions which is being accessed using REST API methodology by Fast API. Right now, when user request my endpoints, each method is processed synchronously.

async def endpoint1(param1, param2):
    return await some_async_method1()
async def endpoint2(param1, param2):
    return await some_async_method2()

etc.

I have tried asyncio gather, however, I do not know when or which endpoints will be called. Thus, I cannot give list of methods to the asyncio gather method.

I have tried ThreadPoolExecutor, I kept loosing the return values.

user3666197
  • 1
  • 6
  • 50
  • 92
Katie
  • 21
  • 2
  • Sharing your current code would help us understand what you are trying to do. – Cow Mar 23 '22 at 07:24
  • Basically, I have 2 functions to run in parallel but I do not know how many times each will be called or when. I need to run them in parallel and return the result of them without confusion. – Katie Mar 23 '22 at 07:26
  • @Chris Sorry for the confusion, I am editing the question. My methods are calling async methods and they are already defined with async def keyword instead of def alone. Thus, it does not answered my question. Also, thanks. – Katie Mar 23 '22 at 07:34
  • Are these methods IO bound or CPU bound internally? If they never give up time for other tasks to do their thing, you won't magically get them running in parallel by applying async/await to them. – MatsLindh Mar 23 '22 at 08:37

0 Answers0