diff --git a/common/common/segments.py b/common/common/segments.py index e62c1d7..6969942 100644 --- a/common/common/segments.py +++ b/common/common/segments.py @@ -535,10 +535,11 @@ def fast_cut_range(segments, start, end, fixts=None): first = segments[0] if cut_start else None last = segments[-1] if cut_end else None - for segment in segments: + for i, segment in enumerate(segments): # Since long smart cuts can be CPU and disk bound for quite a while, # yield to give other things a chance to run. - gevent.idle() + if i % 1000 == 0: + gevent.idle() if segment is None: logging.debug("Skipping discontinuity while cutting") diff --git a/restreamer/restreamer/generate_hls.py b/restreamer/restreamer/generate_hls.py index c79e935..318ed54 100644 --- a/restreamer/restreamer/generate_hls.py +++ b/restreamer/restreamer/generate_hls.py @@ -69,9 +69,10 @@ def generate_media(segments, base_url): if segments and segments[0] is None: segments = segments[1:] - for segment in segments: + for i, segment in enumerate(segments): # For very large playlists, give other things a chance to run - gevent.idle() + if i % 1000 == 0: + gevent.idle() if segment is None: # Discontinuity. Adding this tag tells the client that we've missed something # and it should start decoding fresh on the next segment. This is required when