admin管理员组文章数量:1332377
I have inherited FastAPI code. I am struggling with one of its endpoints. The endpoints functionality is to receive an audio file from the client, reads the file, create an asyncio task using asyncio.create_task
and then return a token in the response. The client can then use the token to poll the server and get the result of the asyncio task.
The asyncio task basically does some compute intensive tasks like removing silences from the audio, transcribing it and then passing it to ChatGPT for generating a summary.
The Problem
This endpoint works correctly for a single request, but if I try to send 2 requests at the same time, one of the requests finishes successfully and the other request just disappears after some time like it was killed. There are logs for some time but then logs disappear without any errors.
What I have tried
I searched for this issue and found that this issue can be caused by having weak references to background tasks as explained here but assigning the task to a variable did not change anything.
I then used asyncio.TaskGroup
as explained here it actually blocked me from sending the sending request. That is the token did not get generated till the first task did not get completed.
I also used loop.run_in_executor
as has been suggested many times at StackOverflow but this resulted in my single request disappearing. That is even my single request did not produce any logs and it did not complete.
I am using Swagger and Postman to send requests to my server and for multiple requests I am sending the same audio file in both requests (maybe this information would be useful).
Any pointers as to how to resolve the issue or maybe how to identify which part of the code is problematic would be welcome.
P.S. I am not sharing any code because there are many async await calls and I am not really sure which part is problematic.
本文标签: python asyncioConcurrent request disappears in FastAPIStack Overflow
版权声明:本文标题:python asyncio - Concurrent request disappears in FastAPI - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742306076a2449943.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论