3

I have been trying to solve this for 2 weeks and I have not been able to reach a solution. Here is what I am trying to do:

I need a web application in which users can upload a video; the video is going to be transformed using opencv's python API. Since I have Python's API for opencv I decided to create the webapp using Django. Everything is fine to that point.

The problem is that the video transformation is a very long process so I was trying to implement some real time capabilities in order to show the user the video as it is transformed, in other words, I transform a frame and show it to the user inmediatly. I am trying to do this with CoffeScript and io sockets following some examples; however I havent been successful.

My question is; what would be the right approach to add real time capabilities to a Django application ?

2 Answers 2

2

I'd recommend using a non-django service to handle the websockets. Setting up websockets properly is tricky on both the client and server side. Look at pusher.com for a free/cheap solution that will just work and save you a whole lot of hassle.

The initial request to start rendering should kick off the long-lived process, and return with an ID which is used to listen to the websocket for updates.

Once you have your websockets set up, you can send messages to the client about each finished frame. Personally I wouldn't try to push the whole frame down the websocket, but rather just send a message saying the frame is done with a URL to get the frame. Then normal HTTP with its caching and browser niceties moves the big data.

You're definitely not choosing the easy path. The easy path is to have your long-lived render task update the render state in the database, and have the client poll that. Extra server load, but a lot simpler.

2
  • Pusher looks good; I haven't heard about it in this 2 weeks of research. Django does not look like the easy path actually, it is not really helping with my real time needs. The point is that i should stick to python because of the heavy dependence on Python's OpenCV API. If you know any better web based framework in python to accomplish the task I would appreciate to be informed. Thanks for your answer. Nov 22, 2011 at 2:11
  • I have already tried pusher.com and it did the trick. Thanks or your quick and accurate answer. Nov 22, 2011 at 14:33
1

Django itself really is focused on doing one kind of web interface, which is following the HTTP Request/Response pattern. To maintain a persistent connection with clients, which socket.io really makes dead simple, you need to diverge a bit from a normal Django installation.

  1. This article discusses the issue of doing real-time with Django, with the help of Orbited and Twisted. It's rather old, and it relies on Comet, which is not the preferred way of doing real-time these days.

  2. You might benefit a lot by going for Socket.io on the client, and something like Tornado (wiki) + Tornado client for Socket.io. But, if you really want to stick with Django for the web development (which Tornado also provide), you would need to make the two work together internally, each handling their particular use case.

  3. Finally, this other article discusses how to make Django work with gevent (an coroutine-based networking library for Python) and Socket.io, which might well be your best option otherwise.

Don't hesitate to post questions/comments as they pop up!

1
  • Thanks a lot for the answer, I will read the articles carefully to see which of the alternatives could fit in this particular project. Tornado seems primissing by the way Nov 22, 2011 at 2:06

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.