Closed ilayasis closed 5 months ago
Edit with more info
Async support for StreamingHTTPResponse is being added in Django 4.2.
Async support for StreamingHTTPResponse is being added in Django 4.2.
Hi, tnx for the quick response, Django 4.2 version by the docs is UNDER DEVELOPMENT and I looking for a solution for right now.
Then you'd need to patch The response object (and asgi handler) in Django.
If you find the commit in Django you can get the patch you need.
I'm actually not familiar with how to do it actually, u have some suggestions on how I can do it in my code?
Or maybe you have some idea which library I can use in Django if want to create a socket, in the end, my goal is to "listen" for only one variable. the consumer that In my code for now it's just for the example.
You have to make the whole code async so test with a initial for loop and yield function and slowly start adding more code to it. And split it into more functions and use await with run_in_executor to make the sync code kind of like a async function.
And cap has to be used like
with concurrent.futures.ThreadPoolExecutor():
while cap.isOpened():
success, frame = await asyncio.to_thread(cap.read)
else you will get the async_generator error.
I add channels to my project and it's creating a problem, I have a stream func that streama video with streaminghttpresponse , and that work well before I add asgi/channels to run the server . I saw that it's some bug that will be fixed in django 4.2 ,but I look for solution for now/ or if someone suggests another library for a socket that will not cause a similar problem
this is my code
Django v - 4.0 channels - 3.0.5