Reputation: 1134
I'm building a fairly simple application with Autobahn for WebSocket functionality. It's very similar to a chat server, but one thing I need to do is understand how to accomplish is how to essentially share resources between the WebSocketServerFactory object and my Flask application. The example here:
https://github.com/tavendo/AutobahnPython/tree/master/examples/twisted/websocket/echo_wsgi
shows how to combine both Flask and Autobahn, but in my particular use case, I want to be able to dynamically add a chat room when triggered by an authorized call from the Flask component. Is there any sort of best practice on how to go about communicating between the two components in Autobahn?
Upvotes: 1
Views: 1239
Reputation: 22051
Flask is based on WSGI, which is a fundamentally blocking API. This doesn't blend well with Twisted or asyncio (the 2 asynchronous network frameworks supported by AutobahnPython).
Here are 2 options:
callFromThread
to communicate from a background thread running WSGI to the main thread running AutobahnUpvotes: 4