Suppress harmless asyncio invalid file descriptor traceback in Spaces logs
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import io
|
| 2 |
import os
|
| 3 |
import shutil
|
|
|
|
| 4 |
from datetime import datetime
|
| 5 |
from functools import lru_cache
|
| 6 |
from pathlib import Path
|
|
@@ -18,6 +19,22 @@ CM_INIT = {"tp": 0, "fp": 0, "fn": 0, "tn": 0}
|
|
| 18 |
EVAL_CLASSES = ["Sesuai", "Tidak Sesuai"]
|
| 19 |
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
def resolve_model_path(model_choice: str) -> str:
|
| 22 |
model_env = os.getenv("MODEL_PATH", "").strip()
|
| 23 |
base_dir = os.path.dirname(__file__)
|
|
|
|
| 1 |
import io
|
| 2 |
import os
|
| 3 |
import shutil
|
| 4 |
+
import asyncio
|
| 5 |
from datetime import datetime
|
| 6 |
from functools import lru_cache
|
| 7 |
from pathlib import Path
|
|
|
|
| 19 |
EVAL_CLASSES = ["Sesuai", "Tidak Sesuai"]
|
| 20 |
|
| 21 |
|
| 22 |
+
# Gradio/Spaces can trigger noisy asyncio cleanup traces ("Invalid file descriptor: -1")
|
| 23 |
+
# during loop finalization. This keeps logs clean without affecting runtime behavior.
|
| 24 |
+
_orig_loop_del = asyncio.BaseEventLoop.__del__
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def _safe_loop_del(self):
|
| 28 |
+
try:
|
| 29 |
+
_orig_loop_del(self)
|
| 30 |
+
except ValueError as err:
|
| 31 |
+
if "Invalid file descriptor" not in str(err):
|
| 32 |
+
raise
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
asyncio.BaseEventLoop.__del__ = _safe_loop_del
|
| 36 |
+
|
| 37 |
+
|
| 38 |
def resolve_model_path(model_choice: str) -> str:
|
| 39 |
model_env = os.getenv("MODEL_PATH", "").strip()
|
| 40 |
base_dir = os.path.dirname(__file__)
|