Jacek Zadrożny commited on
Commit ·
77bf306
1
Parent(s): 637ed9b
Fix signal error in background thread
Browse files- Remove signal-based timeout (doesn't work in threads)
- Simplify to basic background initialization
- Update HUGGINGFACE_DEBUG.md with correct approach
- HUGGINGFACE_DEBUG.md +17 -12
- agent/__pycache__/__init__.cpython-312.pyc +0 -0
- agent/__pycache__/a11y_agent.cpython-312.pyc +0 -0
- agent/__pycache__/prompts.cpython-312.pyc +0 -0
- agent/__pycache__/tools.cpython-312.pyc +0 -0
- app.py +10 -31
- database/__pycache__/__init__.cpython-312.pyc +0 -0
- database/__pycache__/vector_store_client.cpython-312.pyc +0 -0
- models/__pycache__/__init__.cpython-312.pyc +0 -0
- models/__pycache__/embeddings.cpython-312.pyc +0 -0
HUGGINGFACE_DEBUG.md
CHANGED
|
@@ -44,21 +44,26 @@ def validate_api_key(cls, v):
|
|
| 44 |
return v
|
| 45 |
```
|
| 46 |
|
| 47 |
-
#### 3.
|
| 48 |
```python
|
| 49 |
def initialize_agent_background():
|
| 50 |
-
"""Inicjalizacja
|
| 51 |
-
|
| 52 |
-
raise TimeoutError("Timeout after 30 seconds")
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
```
|
| 63 |
|
| 64 |
#### 4. Bezpieczne tworzenie katalogów
|
|
|
|
| 44 |
return v
|
| 45 |
```
|
| 46 |
|
| 47 |
+
#### 3. Background thread initialization
|
| 48 |
```python
|
| 49 |
def initialize_agent_background():
|
| 50 |
+
"""Inicjalizacja agenta w tle bez blokowania startu UI."""
|
| 51 |
+
global agent_instance, agent_ready, agent_error
|
|
|
|
| 52 |
|
| 53 |
+
try:
|
| 54 |
+
logger.info("🔄 Starting agent initialization in background...")
|
| 55 |
+
time.sleep(2) # Unikaj race condition
|
| 56 |
+
agent_instance = create_agent()
|
| 57 |
+
agent_ready = True
|
| 58 |
+
logger.success("✅ A11y Expert Agent is ready!")
|
| 59 |
+
except Exception as e:
|
| 60 |
+
logger.error(f"❌ Failed to initialize agent: {e}")
|
| 61 |
+
agent_error = str(e)
|
| 62 |
+
agent_instance = None
|
| 63 |
+
|
| 64 |
+
# Start w osobnym wątku (daemon)
|
| 65 |
+
init_thread = threading.Thread(target=initialize_agent_background, daemon=True)
|
| 66 |
+
init_thread.start()
|
| 67 |
```
|
| 68 |
|
| 69 |
#### 4. Bezpieczne tworzenie katalogów
|
agent/__pycache__/__init__.cpython-312.pyc
CHANGED
|
Binary files a/agent/__pycache__/__init__.cpython-312.pyc and b/agent/__pycache__/__init__.cpython-312.pyc differ
|
|
|
agent/__pycache__/a11y_agent.cpython-312.pyc
CHANGED
|
Binary files a/agent/__pycache__/a11y_agent.cpython-312.pyc and b/agent/__pycache__/a11y_agent.cpython-312.pyc differ
|
|
|
agent/__pycache__/prompts.cpython-312.pyc
CHANGED
|
Binary files a/agent/__pycache__/prompts.cpython-312.pyc and b/agent/__pycache__/prompts.cpython-312.pyc differ
|
|
|
agent/__pycache__/tools.cpython-312.pyc
CHANGED
|
Binary files a/agent/__pycache__/tools.cpython-312.pyc and b/agent/__pycache__/tools.cpython-312.pyc differ
|
|
|
app.py
CHANGED
|
@@ -32,41 +32,20 @@ agent_error = None
|
|
| 32 |
|
| 33 |
# --- Agent Initialization ---
|
| 34 |
def initialize_agent_background():
|
| 35 |
-
"""Initialize the agent in background thread
|
| 36 |
global agent_instance, agent_ready, agent_error
|
| 37 |
|
| 38 |
-
def _init_with_timeout():
|
| 39 |
-
import time
|
| 40 |
-
import signal
|
| 41 |
-
|
| 42 |
-
def timeout_handler(signum, frame):
|
| 43 |
-
raise TimeoutError("Agent initialization timed out after 30 seconds")
|
| 44 |
-
|
| 45 |
-
try:
|
| 46 |
-
# Set 30 second timeout for Unix-like systems
|
| 47 |
-
if hasattr(signal, 'SIGALRM'):
|
| 48 |
-
signal.signal(signal.SIGALRM, timeout_handler)
|
| 49 |
-
signal.alarm(30)
|
| 50 |
-
|
| 51 |
-
logger.info("🔄 Starting agent initialization in background...")
|
| 52 |
-
time.sleep(2)
|
| 53 |
-
agent_instance = create_agent()
|
| 54 |
-
agent_ready = True
|
| 55 |
-
logger.success("✅ A11y Expert Agent is ready!")
|
| 56 |
-
|
| 57 |
-
# Cancel timeout
|
| 58 |
-
if hasattr(signal, 'SIGALRM'):
|
| 59 |
-
signal.alarm(0)
|
| 60 |
-
|
| 61 |
-
except Exception as e:
|
| 62 |
-
logger.error(f"❌ Failed to initialize agent: {e}")
|
| 63 |
-
import traceback
|
| 64 |
-
logger.error(traceback.format_exc())
|
| 65 |
-
raise
|
| 66 |
-
|
| 67 |
try:
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
except Exception as e:
|
|
|
|
|
|
|
|
|
|
| 70 |
agent_error = str(e)
|
| 71 |
agent_instance = None
|
| 72 |
|
|
|
|
| 32 |
|
| 33 |
# --- Agent Initialization ---
|
| 34 |
def initialize_agent_background():
|
| 35 |
+
"""Initialize the agent in background thread."""
|
| 36 |
global agent_instance, agent_ready, agent_error
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
try:
|
| 39 |
+
logger.info("🔄 Starting agent initialization in background...")
|
| 40 |
+
import time
|
| 41 |
+
time.sleep(2)
|
| 42 |
+
agent_instance = create_agent()
|
| 43 |
+
agent_ready = True
|
| 44 |
+
logger.success("✅ A11y Expert Agent is ready!")
|
| 45 |
except Exception as e:
|
| 46 |
+
logger.error(f"❌ Failed to initialize agent: {e}")
|
| 47 |
+
import traceback
|
| 48 |
+
logger.error(traceback.format_exc())
|
| 49 |
agent_error = str(e)
|
| 50 |
agent_instance = None
|
| 51 |
|
database/__pycache__/__init__.cpython-312.pyc
CHANGED
|
Binary files a/database/__pycache__/__init__.cpython-312.pyc and b/database/__pycache__/__init__.cpython-312.pyc differ
|
|
|
database/__pycache__/vector_store_client.cpython-312.pyc
CHANGED
|
Binary files a/database/__pycache__/vector_store_client.cpython-312.pyc and b/database/__pycache__/vector_store_client.cpython-312.pyc differ
|
|
|
models/__pycache__/__init__.cpython-312.pyc
CHANGED
|
Binary files a/models/__pycache__/__init__.cpython-312.pyc and b/models/__pycache__/__init__.cpython-312.pyc differ
|
|
|
models/__pycache__/embeddings.cpython-312.pyc
CHANGED
|
Binary files a/models/__pycache__/embeddings.cpython-312.pyc and b/models/__pycache__/embeddings.cpython-312.pyc differ
|
|
|