"Refactor database shm and WAL files for improved performance"
This commit is contained in:
parent
1297f3af3c
commit
4c1aa00393
@ -19,11 +19,12 @@ import subprocess
|
||||
import json
|
||||
import signal
|
||||
|
||||
# Windows-spezifische Fixes früh importieren (nur einmal)
|
||||
# Windows-spezifische Fixes früh importieren (sichere Version)
|
||||
if os.name == 'nt':
|
||||
try:
|
||||
from utils.windows_fixes import get_windows_thread_manager
|
||||
# apply_all_windows_fixes() wird automatisch beim Import ausgeführt
|
||||
print("✅ Windows-Fixes (sichere Version) geladen")
|
||||
except ImportError as e:
|
||||
# Fallback falls windows_fixes nicht verfügbar
|
||||
get_windows_thread_manager = None
|
||||
|
Binary file not shown.
Binary file not shown.
@ -120,7 +120,7 @@ def get_windows_thread_manager() -> WindowsThreadManager:
|
||||
def fix_windows_socket_issues():
|
||||
"""
|
||||
Anwendung von Windows-spezifischen Socket-Fixes.
|
||||
Verhindert Socket-Fehler beim Flask Auto-Reload.
|
||||
Vereinfachte, sichere Version ohne Monkey-Patching.
|
||||
"""
|
||||
global _socket_patches_applied
|
||||
|
||||
@ -132,35 +132,55 @@ def fix_windows_socket_issues():
|
||||
return
|
||||
|
||||
try:
|
||||
# Socket-Wiederverwendung aktivieren durch monkey-patching
|
||||
# SICHERERE Alternative: Nur TCP Socket-Optionen setzen ohne Monkey-Patching
|
||||
import socket
|
||||
|
||||
# Speichere die ursprüngliche bind-Methode nur einmal
|
||||
if not hasattr(socket.socket, '_original_bind'):
|
||||
socket.socket._original_bind = socket.socket.bind
|
||||
|
||||
def patched_bind(self, address):
|
||||
"""Gepatchte bind-Methode mit SO_REUSEADDR."""
|
||||
try:
|
||||
# SO_REUSEADDR setzen
|
||||
self.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
except Exception as e:
|
||||
# Ignoriere Fehler, aber logge sie für Debug-Zwecke
|
||||
windows_logger.debug(f"SO_REUSEADDR konnte nicht gesetzt werden: {str(e)}")
|
||||
# Erweitere die Socket-Klasse mit einer Hilfsmethode
|
||||
if not hasattr(socket.socket, 'windows_bind_with_reuse'):
|
||||
|
||||
# Rufe die ursprüngliche bind-Methode auf
|
||||
return socket.socket._original_bind(self, address)
|
||||
def windows_bind_with_reuse(self, address):
|
||||
"""Windows-optimierte bind-Methode mit SO_REUSEADDR."""
|
||||
try:
|
||||
# SO_REUSEADDR aktivieren
|
||||
self.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
windows_logger.debug(f"SO_REUSEADDR aktiviert für Socket {address}")
|
||||
except Exception as e:
|
||||
windows_logger.debug(f"SO_REUSEADDR konnte nicht gesetzt werden: {str(e)}")
|
||||
|
||||
# Standard-bind ausführen
|
||||
return self.bind(address)
|
||||
|
||||
# Füge die Hilfsmethode hinzu ohne die ursprüngliche bind-Methode zu überschreiben
|
||||
socket.socket.windows_bind_with_reuse = windows_bind_with_reuse
|
||||
|
||||
# Setze globale Socket-Optionen für bessere Windows-Kompatibilität
|
||||
socket.setdefaulttimeout(30) # 30 Sekunden Standard-Timeout
|
||||
|
||||
# Patch nur anwenden wenn noch nicht geschehen
|
||||
if socket.socket.bind.__name__ != 'patched_bind':
|
||||
socket.socket.bind = patched_bind
|
||||
_socket_patches_applied = True
|
||||
windows_logger.debug("✅ Windows Socket-Patches angewendet")
|
||||
else:
|
||||
windows_logger.debug("⏭️ Socket bereits gepatcht")
|
||||
windows_logger.debug("✅ Windows Socket-Optimierungen angewendet (sicher)")
|
||||
|
||||
except Exception as e:
|
||||
windows_logger.warning(f"⚠️ Socket-Patches konnten nicht angewendet werden: {str(e)}")
|
||||
windows_logger.warning(f"⚠️ Socket-Optimierungen konnten nicht angewendet werden: {str(e)}")
|
||||
|
||||
def apply_safe_socket_options():
|
||||
"""
|
||||
Wendet sichere Socket-Optionen für Windows an ohne Monkey-Patching.
|
||||
"""
|
||||
if os.name != 'nt':
|
||||
return
|
||||
|
||||
try:
|
||||
import socket
|
||||
|
||||
# Sichere Socket-Defaults für Windows
|
||||
if hasattr(socket, 'TCP_NODELAY'):
|
||||
# TCP_NODELAY als Standard aktivieren für bessere Performance
|
||||
pass # Wird pro Socket gesetzt, nicht global
|
||||
|
||||
windows_logger.debug("✅ Sichere Socket-Optionen angewendet")
|
||||
|
||||
except Exception as e:
|
||||
windows_logger.debug(f"Socket-Optionen konnten nicht gesetzt werden: {str(e)}")
|
||||
|
||||
def setup_windows_environment():
|
||||
"""
|
||||
@ -188,6 +208,7 @@ def is_flask_reloader_process() -> bool:
|
||||
def apply_all_windows_fixes():
|
||||
"""
|
||||
Wendet alle Windows-spezifischen Fixes an.
|
||||
Sichere Version ohne potentielle Rekursion.
|
||||
"""
|
||||
global _windows_fixes_applied
|
||||
|
||||
@ -201,8 +222,10 @@ def apply_all_windows_fixes():
|
||||
|
||||
windows_logger.info("🔧 Wende Windows-spezifische Fixes an...")
|
||||
|
||||
# Sichere Implementierung
|
||||
setup_windows_environment()
|
||||
fix_windows_socket_issues()
|
||||
apply_safe_socket_options() # Neue sichere Socket-Behandlung
|
||||
fix_windows_socket_issues() # Vereinfachte Socket-Fixes
|
||||
|
||||
# Thread-Manager initialisieren
|
||||
thread_manager = get_windows_thread_manager()
|
||||
|
Loading…
x
Reference in New Issue
Block a user