Spaces:
Running on Zero
Running on Zero
gradio asyncio bug
Browse files- gradio_app.py +29 -0
gradio_app.py
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
import gc
|
|
|
|
| 1 |
+
def _patch_asyncio_event_loop_del():
|
| 2 |
+
"""
|
| 3 |
+
Patch a noisy asyncio teardown issue sometimes seen in Spaces environments.
|
| 4 |
+
In some runtime/container combinations, Python may try to close an already
|
| 5 |
+
invalid file descriptor when the event loop is garbage-collected. We silence
|
| 6 |
+
only that specific harmless case.
|
| 7 |
+
"""
|
| 8 |
+
try:
|
| 9 |
+
import asyncio.base_events as base_events
|
| 10 |
+
|
| 11 |
+
original_del = getattr(base_events.BaseEventLoop, "__del__", None)
|
| 12 |
+
if original_del is None:
|
| 13 |
+
return
|
| 14 |
+
|
| 15 |
+
def patched_del(self):
|
| 16 |
+
try:
|
| 17 |
+
original_del(self)
|
| 18 |
+
except ValueError as e:
|
| 19 |
+
if "Invalid file descriptor" not in str(e):
|
| 20 |
+
raise
|
| 21 |
+
|
| 22 |
+
base_events.BaseEventLoop.__del__ = patched_del
|
| 23 |
+
except Exception:
|
| 24 |
+
pass
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
_patch_asyncio_event_loop_del()
|
| 28 |
+
|
| 29 |
+
|
| 30 |
import os
|
| 31 |
import sys
|
| 32 |
import gc
|