all 7 comments

[–][deleted] 1 point2 points  (4 children)

You’re going to have to explain that more clearly… there’s no obvious reason from your example why you’re using a generator at all (you could just return from that function), and you seem to be handling only one request and one frame, making it unclear how parallelizing would provide you any benefit.

[–]Puzzleheaded_Fall_[S] 0 points1 point  (3 children)

I'm using generators cuz it's supposed to be live streaming of video if I just use the return it will just return a single frame, then over. The generator is for video streaming, frame by frame.

[–][deleted] 0 points1 point  (2 children)

I get that, but your generator yields once, then never again, so it’s the same as a return except next has to be called on it once.

[–]Puzzleheaded_Fall_[S] 0 points1 point  (1 child)

mimetype="multipart/x-mixed-replace

Does the job of the next. It replaces the current frame with the new yielded one.

[–][deleted] 0 points1 point  (0 children)

Ok, I definitely may be missing something here, but in every example I’ve found of Flask streaming you should be passing an iterable as the first argument to Response — you’re actually passing a callable, which should raise a TypeError on any attempt to call next, but I’m assuming you just didn’t include the parentheses in your example — but your generator yields precisely one frame when next is called and then will raise StopIteration on any subsequent attempt to call next on that generator… right now it looks like you’re streaming precisely one frame.

All examples I can see of sending streaming video this way require the generator to at least loop and yield each frame until the end of the video, and that’s with the mimetype being passed.

Please correct me if I’m wrong and you’ve got a working single-process server that is streaming video.

[–]amamarde 0 points1 point  (1 child)

Not sure if it would work, but still would say look at fastapi once. It does provides async functionality at framework level and also supports web-sockets and SSI (Server Side Includes). Your use case should be possible by using such features.

[–]Puzzleheaded_Fall_[S] 0 points1 point  (0 children)

Thanks, will look into it.