When accepting connections in a multi-process environment, it is highly likely that the coroutine will be blocked. #2664
              
                Unanswered
              
          
                  
                    
                      godtang
                    
                  
                
                  asked this question in
                Potential Issue
              
            Replies: 3 comments 7 replies
-
| 
         I can't reproduce this.  | 
  
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            -
        20250716-144335.mp4@Kludex here is video, i'm certain that this problem has occurred on at least three machines in the company.  | 
  
Beta Was this translation helpful? Give feedback.
                  
                    7 replies
                  
                
            -
| 
         Can't reproduce it. Before digging further make sure you keep a strong reference to the task because in this case: the startup event handler exits immediately. And the created task may not survive or may be GCed at some point. app.state.bg_task = set()
@app.on_event("startup")
async def start_print_loop():
    app.state.bg_task.add(asyncio.create_task(print_loop()))
    print('exited') | 
  
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    

Uh oh!
There was an error while loading. Please reload this page.
-
use command
uvicorn main:app --host 0.0.0.0 --port 22222 --workers 2runAfter connecting to port 22222 multiple times, the following situation will occur as shown in the figure. If you reconnect, the coroutine printing can be resumed.
On my computer, it can be replicated within 5 connections. However, my colleague's computer requires more than 20 attempts.
Beta Was this translation helpful? Give feedback.
All reactions