From c11ce048c7fc60676a2e83cf8d5d149c36fb6e1c Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Thu, 1 May 2025 09:24:16 -0500 Subject: [PATCH 1/3] Disable monkey patching. --- docker/uwsgi.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/uwsgi.ini b/docker/uwsgi.ini index b1ff362b..b40259c2 100644 --- a/docker/uwsgi.ini +++ b/docker/uwsgi.ini @@ -41,7 +41,7 @@ lazy-apps = true # Improve memory efficiency # Async mode (use gevent for high concurrency) gevent = 100 async = 100 -gevent-monkey-patch = true ; Ensure all blocking operations are patched (especially important for Ryzen CPUs) +#gevent-monkey-patch = true ; Ensure all blocking operations are patched (especially important for Ryzen CPUs) # Performance tuning thunder-lock = true From e8ee59cf00fd68e86f653efc59890a671cd31867 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Thu, 1 May 2025 09:31:26 -0500 Subject: [PATCH 2/3] Not sure why it didn't push. --- docker/uwsgi.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/docker/uwsgi.ini b/docker/uwsgi.ini index b40259c2..326f4b5d 100644 --- a/docker/uwsgi.ini +++ b/docker/uwsgi.ini @@ -41,7 +41,6 @@ lazy-apps = true # Improve memory efficiency # Async mode (use gevent for high concurrency) gevent = 100 async = 100 -#gevent-monkey-patch = true ; Ensure all blocking operations are patched (especially important for Ryzen CPUs) # Performance tuning thunder-lock = true From b3c4ff8f2d609cc2494f884254d678049595a331 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Thu, 1 May 2025 10:43:07 -0500 Subject: [PATCH 3/3] Finding more timers that can be converted to gevents. --- apps/hdhr/ssdp.py | 3 ++- apps/proxy/ts_proxy/stream_buffer.py | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/hdhr/ssdp.py b/apps/hdhr/ssdp.py index 660d9c2f..d794799a 100644 --- a/apps/hdhr/ssdp.py +++ b/apps/hdhr/ssdp.py @@ -2,6 +2,7 @@ import os import socket import threading import time +import gevent # Add this import from django.conf import settings # SSDP Multicast Address and Port @@ -59,7 +60,7 @@ def ssdp_broadcaster(host_ip): sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) while True: sock.sendto(notify.encode("utf-8"), (SSDP_MULTICAST, SSDP_PORT)) - time.sleep(30) + gevent.sleep(30) # Replace time.sleep with gevent.sleep def start_ssdp(): host_ip = get_host_ip() diff --git a/apps/proxy/ts_proxy/stream_buffer.py b/apps/proxy/ts_proxy/stream_buffer.py index f0be1c52..a5169c3a 100644 --- a/apps/proxy/ts_proxy/stream_buffer.py +++ b/apps/proxy/ts_proxy/stream_buffer.py @@ -12,6 +12,7 @@ from .config_helper import ConfigHelper from .constants import TS_PACKET_SIZE from .utils import get_logger import gevent.event +import gevent # Make sure this import is at the top logger = get_logger() @@ -236,8 +237,8 @@ class StreamBuffer: timers_cancelled = 0 for timer in list(self.fill_timers): try: - if timer and timer.is_alive(): - timer.cancel() + if timer and not timer.dead: # Changed from timer.is_alive() + timer.kill() # Changed from timer.cancel() timers_cancelled += 1 except Exception as e: logger.error(f"Error canceling timer: {e}") @@ -325,8 +326,7 @@ class StreamBuffer: if self.stopping: return None - timer = threading.Timer(delay, callback, args=args, kwargs=kwargs) - timer.daemon = True - timer.start() + # Replace threading.Timer with gevent.spawn_later for better compatibility + timer = gevent.spawn_later(delay, callback, *args, **kwargs) self.fill_timers.append(timer) return timer