fffiloni commited on
Commit
5de27dd
·
verified ·
1 Parent(s): 0a5d069

patch asyncio warnings with gradio

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