diff --git a/foodie_utils.py b/foodie_utils.py index 91f881b..206df51 100644 --- a/foodie_utils.py +++ b/foodie_utils.py @@ -1693,30 +1693,16 @@ def is_any_script_running(): if entry.get("status") == "running" and entry.get("pid"): try: # Verify the process is still running + import psutil process = psutil.Process(entry["pid"]) if process.is_running(): - logger.debug(f"Active script detected: {entry['script_name']} (PID: {entry['pid']})") return True - else: - # Process is dead, mark as stopped - entry["status"] = "stopped" - entry["stop_time"] = datetime.now(timezone.utc).isoformat() - entry["pid"] = None - logger.debug(f"Marked stale script as stopped: {entry['script_name']}") - except psutil.NoSuchProcess: - # Process doesn't exist, mark as stopped - entry["status"] = "stopped" - entry["stop_time"] = datetime.now(timezone.utc).isoformat() - entry["pid"] = None - logger.debug(f"Marked stale script as stopped: {entry['script_name']}") - - # Save updated activities if any were marked as stopped - save_json_file(activity_file, activities) - logger.debug("No active scripts detected") + except Exception: + continue return False except Exception as e: - logger.error(f"Failed to check system_activity.json: {e}") - return False + logging.error(f"Failed to check system_activity.json: {e}") + return False def initialize_rate_limit_info(): """