Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async/await support for flask-socketio #2112

Open
Ashif4354 opened this issue Nov 13, 2024 · 2 comments
Open

async/await support for flask-socketio #2112

Ashif4354 opened this issue Nov 13, 2024 · 2 comments

Comments

@Ashif4354
Copy link

Is your feature request related to a problem? Please describe.
Flask-SocketIO currently doesn’t support async def event listeners, async methods in class-based namespaces, or async/await syntax. This limits developers from fully utilizing async functionality within the framework, leading to workarounds and increased complexity.

Describe the solution you'd like
I propose adding support for:

  1. async def event listeners.
  2. Async methods in class-based namespaces.
  3. Full async/await syntax support for event handling in Flask-SocketIO.
    This would allow Flask-SocketIO users to write clean, async code directly within the framework.

Describe alternatives you've considered
I’ve considered using Flask with the async extra and python-socketio separately, but this requires additional setup and increases complexity. Adding async support to Flask-SocketIO would provide a seamless solution within the existing framework.

Additional context
Enabling async support in Flask-SocketIO would make it more powerful and scalable for real-time applications, making the framework more appealing to developers looking for async solutions.

@Ashif4354
Copy link
Author

I am also interested in implemeting this feature

@miguelgrinberg
Copy link
Owner

I am open to merging a PR that adds this, but fair warning, this isn't going to be as great as you seem to think it will be.

Full async/await syntax support for event handling in Flask-SocketIO.

Full async support is not possible, in the same way it isn't possible for Flask.

I’ve considered using Flask with the async extra and python-socketio separately

This would not work, sadly. Flask remains synchronous internally and cannot integrate with pure async code.

Adding async support to Flask-SocketIO would provide a seamless solution within the existing framework.

The Flask async support is not "seamless", as it has important limitations. See the discussion on performance and background tasks in the Flask docs if you are not familiar with the issues.

But as I said above, a simple PR that adds support for async views is fine, I have no problem with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants