turtle170 commited on
Commit
edc7e75
·
verified ·
1 Parent(s): 695cb69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -4
app.py CHANGED
@@ -255,13 +255,21 @@ class BackendProcessor:
255
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - ZEROENGINE - %(message)s', force=True)
256
  logger = logging.getLogger(__name__)
257
 
258
- # Suppress asyncio warnings during shutdown (targeted approach)
259
  import warnings
260
- warnings.filterwarnings("ignore", category=RuntimeWarning, message=".*asyncio.*")
261
- warnings.filterwarnings("ignore", category=UserWarning, message=".*asyncio.*")
262
 
263
- # Set environment variable to suppress asyncio warnings
264
  os.environ['PYTHONASYNCIODEBUG'] = '0'
 
 
 
 
 
 
 
 
265
 
266
  # Store original get_event_loop for restoration
267
  import asyncio
@@ -280,6 +288,21 @@ def _safe_get_event_loop():
280
  # Replace with safe version
281
  asyncio.get_event_loop = _safe_get_event_loop
282
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
  # --- KERNEL INITIALIZATION ---
284
  try:
285
  from llama_cpp import Llama
 
255
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - ZEROENGINE - %(message)s', force=True)
256
  logger = logging.getLogger(__name__)
257
 
258
+ # Comprehensive asyncio warning suppression (multiple layers)
259
  import warnings
260
+ import sys
261
+ import os
262
 
263
+ # Set environment variables to suppress asyncio warnings
264
  os.environ['PYTHONASYNCIODEBUG'] = '0'
265
+ os.environ['ASYNCIO_DEBUG'] = '0'
266
+
267
+ # Suppress all asyncio-related warnings at the Python level
268
+ warnings.filterwarnings("ignore", category=RuntimeWarning, message=".*asyncio.*")
269
+ warnings.filterwarnings("ignore", category=UserWarning, message=".*asyncio.*")
270
+ warnings.filterwarnings("ignore", category=DeprecationWarning, message=".*asyncio.*")
271
+ warnings.filterwarnings("ignore", message=".*file descriptor.*")
272
+ warnings.filterwarnings("ignore", message=".*Invalid file descriptor.*")
273
 
274
  # Store original get_event_loop for restoration
275
  import asyncio
 
288
  # Replace with safe version
289
  asyncio.get_event_loop = _safe_get_event_loop
290
 
291
+ # Also suppress the BaseEventLoop.__del__ warnings by customizing the exception handler
292
+ _original_excepthook = sys.excepthook
293
+
294
+ def _custom_excepthook(exc_type, exc_value, exc_traceback):
295
+ # Suppress asyncio file descriptor errors
296
+ if (exc_type == ValueError and
297
+ "Invalid file descriptor" in str(exc_value) and
298
+ "BaseEventLoop" in str(exc_traceback)):
299
+ return # Suppress the error
300
+ # Call original handler for other exceptions
301
+ _original_excepthook(exc_type, exc_value, exc_traceback)
302
+
303
+ # Install custom exception hook
304
+ sys.excepthook = _custom_excepthook
305
+
306
  # --- KERNEL INITIALIZATION ---
307
  try:
308
  from llama_cpp import Llama