How can change gunicorn worker from the default 'sync' to 'eventlet' so that I can use socketio for a python/flask web deployed on Azure App Services?

Minhong Mi 0 Reputation points
2024-01-06T01:22:52.8933333+00:00

I was trying to use the flask-socketio package to send/receive data from a Python/Flask web app deployed to the Azure App Services (Linux B1), but came into issues when the client started to send data to the server with the fetch (POST) command.

It is my understanding that the flask-socketio package requires the eventlet or gevent , instead of the default 'sync', workers to support the asynchronous opeations.

So, I added the "GUNICORN_CMD_ARGS" with value of " --workers=1 --worker-class=eventlet my_app:app" to the app settings as suggested by chat-GPT, and restarted the app several times, only to see gunicorn still starting with the 'sync' worker in the log stream.

Can I anyone help here?

Thanks!

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
{count} votes

1 answer

Sort by: Most helpful
  1. Sedat SALMAN 14,280 Reputation points MVP Volunteer Moderator
    2024-01-07T11:11:11.74+00:00

    eventlet is required for Gunicorn to use the eventlet worker class so ensure that itis installed in your environment and then Update your startup command in Azure App Services to specify the eventlet worker.

    gunicorn --bind=0.0.0.0 --timeout 600 --access-logfile '-' --error-logfile '-' --worker-class eventlet app:app
    

    restart your Azure App Service

    start your application

    gunicorn --worker-class eventlet -w 1 module:app
    
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.