🐶
I have a Flask app that I recently separated into blueprints as it grew in size.
All of the app migrated well except for one thing – socketio.
My goal is to have a socketio background task run in on my server, but to have all of it’s configuration in a separate blueprint.
I can’t figure out how to use the main app’s socketio instance inside of another blueprint.
So far I ran into 2 main issues:
- I tried to tell
blueprint.py
to importmain.py
‘s socketio, and also tellmain.py
to importblueprint.py
. That results in the expected circular import error. - After that I searched online for a configuration of some sort and the only config I found https://github.com/miguelgrinberg/Flask-SocketIO-Chat), suggested creating socketio in a separate file, and then importing it by both
main.py
andblueprint.py
to avoid the last error.
But this always raised an issue whereblueprint.py
tried to use socketio before it has initialized.
(This is also what ChatGPT suggested).
It’s crazy how little information I was able to find about this…
If anyone ran into this before I’d appreciate any help I can get!
Guy Shalom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1