Parcourir la source

claude doing clause things

zehe il y a 3 mois
Parent
commit
b0745ec473
1 fichiers modifiés avec 25 ajouts et 13 suppressions
  1. 25 13
      main.py

+ 25 - 13
main.py

@@ -122,22 +122,34 @@ def send_ntfy_notification(backends: List[str], message: str, title: str = None)
                 ntfy_config = load_config(config.ntfy_config_path)
                 ntfy_config["backends"] = [backend]
 
-                # Add timeout to prevent hanging
-                import signal
-                def timeout_handler(signum, frame):
+                # Add timeout to prevent hanging using threading
+                import threading
+
+                result = [None]
+                exception = [None]
+
+                def notify_with_timeout():
+                    try:
+                        # Send notification using the backend name from our config file
+                        if title:
+                            result[0] = ntfy.notify(message, title=title, config=ntfy_config)
+                        else:
+                            result[0] = ntfy.notify(message, config=ntfy_config, title="Note")
+                    except Exception as e:
+                        exception[0] = e
+
+                thread = threading.Thread(target=notify_with_timeout)
+                thread.daemon = True
+                thread.start()
+                thread.join(timeout=15)  # 15 second timeout
+
+                if thread.is_alive():
                     raise Exception("Notification timeout")
 
-                signal.signal(signal.SIGALRM, timeout_handler)
-                signal.alarm(15)  # 15 second timeout
+                if exception[0]:
+                    raise exception[0]
 
-                try:
-                    # Send notification using the backend name from our config file
-                    if title:
-                        ret = ntfy.notify(message, title=title, config=ntfy_config)
-                    else:
-                        ret = ntfy.notify(message, config=ntfy_config, title="Note")
-                finally:
-                    signal.alarm(0)  # Cancel timeout
+                ret = result[0]
 
                 if ret == 0:
                     successful_backends.append(backend)