mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-01-23 02:35:14 +00:00
Finding more timers that can be converted to gevents.
This commit is contained in:
parent
e8ee59cf00
commit
b3c4ff8f2d
2 changed files with 7 additions and 6 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue