feat: Suppress asyncio event loop warnings on HF Spaces shutdown
Browse files
app.py
CHANGED
|
@@ -12,6 +12,18 @@ from pathlib import Path
|
|
| 12 |
warnings.filterwarnings("ignore", message=".*Invalid file descriptor.*")
|
| 13 |
logging.getLogger("asyncio").setLevel(logging.CRITICAL)
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# Set environment for Hugging Face Spaces
|
| 16 |
os.environ['GRADIO_SERVER_NAME'] = '0.0.0.0'
|
| 17 |
os.environ['GRADIO_SERVER_PORT'] = '7860'
|
|
|
|
| 12 |
warnings.filterwarnings("ignore", message=".*Invalid file descriptor.*")
|
| 13 |
logging.getLogger("asyncio").setLevel(logging.CRITICAL)
|
| 14 |
|
| 15 |
+
# Suppress "Exception ignored in: BaseEventLoop.__del__" on HF Spaces shutdown
|
| 16 |
+
# warnings.filterwarnings does NOT catch these — they go via sys.unraisablehook
|
| 17 |
+
_original_unraisablehook = sys.unraisablehook
|
| 18 |
+
|
| 19 |
+
def _suppress_asyncio_fd_errors(unraisable):
|
| 20 |
+
if (unraisable.exc_type is ValueError and
|
| 21 |
+
"Invalid file descriptor" in str(unraisable.exc_value)):
|
| 22 |
+
return # silently ignore
|
| 23 |
+
_original_unraisablehook(unraisable)
|
| 24 |
+
|
| 25 |
+
sys.unraisablehook = _suppress_asyncio_fd_errors
|
| 26 |
+
|
| 27 |
# Set environment for Hugging Face Spaces
|
| 28 |
os.environ['GRADIO_SERVER_NAME'] = '0.0.0.0'
|
| 29 |
os.environ['GRADIO_SERVER_PORT'] = '7860'
|