Reputation: 4397
Here is my deal:
After request form curl hits my django app and my view I need to send message to the server to the channel that my website is subscribed on. Basically I need websocket client that can send message to specific channel and can be run in django view (no infinite blocking loop).
I've tried to figure out this over 4 days. I've wrote to writ autobahn pubsub client with twisted.reacotr, but I can send the message only once (after I stop reactor to finish django request I cannot start it again, because it's not restartable).
I've olso tried djagno-socketio, but there is but, so I cannot see clients when I try to send the message from django view.
ws4py doesn't support channels
Thanks for any advice. Great would be an example.
Upvotes: 5
Views: 2004
Reputation: 22011
You should be able to run Django and Autobahn within 1 server:
Here is an example that shows how to use Flask/WSGI with Autobahn. And Django can run in a WSGI container as well.
Also it should be possible to run an Autobahn-based WebSocket client from a Django/WSGI/Twisted based server using above method as well.
The point is: Twisted can act as a WSGI container and will then run the WSGI Web app (which can be blocking) on a background pool of worker threads. This will allow you to use the asynch features of Twisted, and e.g. run Autobahn - either client or server. So you might also rethink the overall architecture: why run the Autobahn server as a different process at all?
Upvotes: 1