turtle170 commited on
Commit
65c2c95
·
verified ·
1 Parent(s): 216aa0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -11
app.py CHANGED
@@ -255,9 +255,17 @@ 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
259
  import warnings
260
  warnings.filterwarnings("ignore", category=RuntimeWarning, message=".*asyncio.*")
 
 
 
 
 
 
 
 
261
 
262
  # --- KERNEL INITIALIZATION ---
263
  try:
@@ -1895,19 +1903,50 @@ if __name__ == "__main__":
1895
  # Final garbage collection with asyncio cleanup
1896
  logger.info("[CLEANUP] Performing final cleanup...")
1897
  try:
 
1898
  import asyncio
1899
- # Close any remaining event loops
 
 
1900
  try:
1901
- loops = asyncio.all_tasks()
1902
- logger.info(f"[CLEANUP] Found {len(loops)} asyncio tasks")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1903
 
1904
- loop = asyncio.get_event_loop()
1905
- if loop and not loop.is_closed():
1906
- logger.info("[CLEANUP] Closing event loop...")
1907
- loop.close()
1908
- logger.info("[CLEANUP] Event loop closed")
1909
- except RuntimeError:
1910
- logger.info("[CLEANUP] No event loop to close")
 
 
 
 
 
1911
 
1912
  # Final GC
1913
  logger.info("[CLEANUP] Running final garbage collection...")
 
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 (multiple methods)
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
+ # Suppress asyncio event loop warnings
267
+ import asyncio
268
+ asyncio.get_event_loop = lambda: None # Prevent event loop access during shutdown
269
 
270
  # --- KERNEL INITIALIZATION ---
271
  try:
 
1903
  # Final garbage collection with asyncio cleanup
1904
  logger.info("[CLEANUP] Performing final cleanup...")
1905
  try:
1906
+ # More aggressive asyncio cleanup
1907
  import asyncio
1908
+ import sys
1909
+
1910
+ # Force close all event loops
1911
  try:
1912
+ # Get all running loops and close them
1913
+ if hasattr(asyncio, 'all_tasks'):
1914
+ tasks = asyncio.all_tasks()
1915
+ logger.info(f"[CLEANUP] Found {len(tasks)} asyncio tasks")
1916
+
1917
+ # Cancel all tasks
1918
+ for task in tasks:
1919
+ if not task.done():
1920
+ task.cancel()
1921
+
1922
+ # Wait for tasks to complete
1923
+ if tasks:
1924
+ asyncio.gather(*tasks, return_exceptions=True)
1925
+ logger.info("[CLEANUP] All tasks cancelled")
1926
+
1927
+ # Close event loops
1928
+ if hasattr(asyncio, 'get_event_loop'):
1929
+ try:
1930
+ loop = asyncio.get_event_loop()
1931
+ if loop and not loop.is_closed():
1932
+ logger.info("[CLEANUP] Closing main event loop...")
1933
+ loop.close()
1934
+ logger.info("[CLEANUP] Main event loop closed")
1935
+ except RuntimeError:
1936
+ logger.info("[CLEANUP] No event loop to close")
1937
 
1938
+ # Try to close any remaining loops
1939
+ if hasattr(asyncio, '_get_running_loop'):
1940
+ try:
1941
+ running_loop = asyncio._get_running_loop()
1942
+ if running_loop:
1943
+ logger.info("[CLEANUP] Closing running loop...")
1944
+ running_loop.close()
1945
+ except:
1946
+ pass
1947
+
1948
+ except Exception as e:
1949
+ logger.info(f"[CLEANUP] Asyncio cleanup note: {e}")
1950
 
1951
  # Final GC
1952
  logger.info("[CLEANUP] Running final garbage collection...")