I've been working with BentoML and encountered a challenge. I'm hoping to get some assistance on this matter. I've developed multiple APIs using BentoML, and the general structure of my script looks like the following:
There are two functions, main1 and main2, which receive requests almost simultaneously. I'm aiming to achieve an asynchronous processing flow where the success message is received before the sub functions are fully executed. However, I'm facing an issue where main1 immediately receives the success message, but it doesn't wait for the completion of the sub1 function before main2 receives its success message.
Current Situation:
- Requests made to main1 and main2
- main1 receives "success1" message
- sub1 function of main1 begins execution
- main2 receives "success2" message
- sub1 function of main1 completes execution
- sub2 function of main2 completes execution
Here is a simplified version of my code:
@svc.api(route='/execute/main1',
input=bentoml.io.JSON(),
output=bentoml.io.JSON())
async def main1():
asyncio.ensure_future(sub1())
return {'message': 'success1'}
@svc.api(route='/execute/main2',
input=bentoml.io.JSON(),
output=bentoml.io.JSON())
async def main2():
asyncio.ensure_future(sub2())
return {'message': 'success2'}
async def sub1():
...
request.post()
async def sub2():
...
requests.post()
If you have any references or advice that could help me achieve the desired behavior, I would greatly appreciate it! Thank you!
Desired Situation:
- Requests made to main1 and main2
- main1 receives "success1" message
- sub1 function of main1 is executing + main2 receives "success2" message
- sub1 function of main1 completes execution
- sub2 function of main2 completes execution