Rthur2003 commited on
Commit
c7e5d79
·
1 Parent(s): 306211a

feat: enhance Windows compatibility for asyncio with warning suppression

Browse files
Files changed (1) hide show
  1. local_demo.py +10 -2
local_demo.py CHANGED
@@ -21,9 +21,17 @@ from dataclasses import dataclass
21
  from pathlib import Path
22
  from typing import Any
23
 
24
- if sys.platform == "win32" and hasattr(asyncio, "WindowsSelectorEventLoopPolicy"):
 
 
 
 
 
 
25
  # Gradio/Uvicorn is more stable with the selector loop on Windows.
26
- asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
 
 
27
 
28
  try:
29
  import gradio as gr
 
21
  from pathlib import Path
22
  from typing import Any
23
 
24
+ WINDOWS_SELECTOR_POLICY = None
25
+ if sys.platform == "win32":
26
+ with warnings.catch_warnings():
27
+ warnings.simplefilter("ignore", category=DeprecationWarning)
28
+ WINDOWS_SELECTOR_POLICY = getattr(asyncio, "WindowsSelectorEventLoopPolicy", None)
29
+
30
+ if WINDOWS_SELECTOR_POLICY is not None:
31
  # Gradio/Uvicorn is more stable with the selector loop on Windows.
32
+ with warnings.catch_warnings():
33
+ warnings.simplefilter("ignore", category=DeprecationWarning)
34
+ asyncio.set_event_loop_policy(WINDOWS_SELECTOR_POLICY())
35
 
36
  try:
37
  import gradio as gr