From 8a84364e0dd08247cd2e023e2a3880aeaf99df35 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 30 Sep 2020 15:42:16 -0400 Subject: [PATCH] Check If Chunk Method can close better --- fakehdhr/__init__.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/fakehdhr/__init__.py b/fakehdhr/__init__.py index 14f07fb..204d8cd 100644 --- a/fakehdhr/__init__.py +++ b/fakehdhr/__init__.py @@ -263,12 +263,16 @@ class HDHR_HTTP_Server(): req = requests.get(channelUri, stream=True) def generate(): - yield '' - for chunk in req.iter_content(chunk_size=hdhr.config["direct_stream"]['chunksize']): - if not duration == 0 and not time.time() < duration: - req.close() - break - yield chunk + try: + yield '' + for chunk in req.iter_content(chunk_size=hdhr.config["direct_stream"]['chunksize']): + if not duration == 0 and not time.time() < duration: + req.close() + break + yield chunk + except GeneratorExit: + req.close() + print("Connection Closed.") return Response(generate(), content_type=req.headers['content-type'], direct_passthrough=True)