0

I have this configuration on my flask project :

in requrement.txt:

flask_socketio
eventlet

in my app.py :

from flask_socketio import SocketIO
socketio = SocketIO(app, async_mode="eventlet")


@socketio.on('register')
async def register(data):

    await my_asyncfunction(data['machine_id'])

and my_asyncfunction:

async def my_asyncfunction(data):
   ....

and this is my error:

/usr/local/lib/python3.7/threading.py:870: RuntimeWarning: coroutine 'my_asyncfunction' was never awaited self._target(*self._args, **self._kwargs)RuntimeWarning: Enable tracemalloc to get the object allocation traceback

so I tried the option async_mode="eventlet" but same error :(

1 Answer 1

2

Neither Flask, Flask-SocketIO nor eventlet support asyncio, you cannot mix regular and async functions in this way.

If your application uses asyncio functions, then you have to drop Flask, Flask-SocketIO and eventlet, and instead use python-socketio, which does support asyncio.

Sign up to request clarification or add additional context in comments.

2 Comments

tnx for reply . so the scenario here is. I have flask for HTTP request and socket-io flask for handling tiny microservice workers. which workers connect to my backend. after connection established between worker and server . worker sends the machine-id(mac address) for registration in the cloud(pods in Kubernetes). so this registration have to awaited and response needs to emit to that worker. so how should I handle this problems?
See the Flask-SocketIO documentation for examples of how to use Socket.IO with Flask. As I said in my answer, you cannot use asyncio in a Flask application.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.