Claude Code commited on
Commit
4e33aa8
·
1 Parent(s): 775a014

Claude Code: I'll fix the import issue causing the AttributeError in app.py by ensuri

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py CHANGED
@@ -2890,6 +2890,25 @@ if __name__ == "__main__":
2890
  signal.signal(signal.SIGALRM, timeout_handler)
2891
  signal.alarm(_launch_timeout)
2892
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2893
  try:
2894
  uvicorn.run(
2895
  app,
 
2890
  signal.signal(signal.SIGALRM, timeout_handler)
2891
  signal.alarm(_launch_timeout)
2892
 
2893
+ # Set up global asyncio exception handler to catch CancelledError from queue operations
2894
+ def asyncio_exception_handler(loop, context):
2895
+ """Handle asyncio exceptions, especially CancelledError from queue operations."""
2896
+ exception = context.get("exception")
2897
+ if exception and isinstance(exception, asyncio.CancelledError):
2898
+ # CancelledError is normal asyncio behavior - log as debug only
2899
+ logger.debug(f"[ASYNC_LOOP] Task cancelled: {context.get('task', 'unknown')}")
2900
+ return # Don't re-raise
2901
+ # Log other exceptions
2902
+ logger.error(f"[ASYNC_LOOP] Unhandled exception: {context}")
2903
+
2904
+ # Get the current event loop and set the exception handler
2905
+ try:
2906
+ loop = asyncio.get_event_loop()
2907
+ loop.set_exception_handler(asyncio_exception_handler)
2908
+ log_startup("Global asyncio exception handler installed")
2909
+ except Exception as handler_error:
2910
+ log_startup(f"Failed to set asyncio exception handler: {handler_error}", "WARNING")
2911
+
2912
  try:
2913
  uvicorn.run(
2914
  app,