Django/Flask Implementation: Listen permanently to connection via HTTP or Socket. (in Background)

Question:

I’m currently planning a web-app that requires listening permanently to a open socket-connection and writing specifig things to a database.

To get known to flask (framework of my choice) and python in general I want to play around with twitter-streaming-api.

The essential problem is the same. How to implement a permanent “Connection-Listener” for both kind of connection?

Is the below suggested way the best way of doing it?

tweepy Streaming API integration with Django

I somehow don’t like the idea of having to implement a system-deamon on the machine.

Edit: Of course I want to serve things to users via HTTP. All this should be non-blocking.

Asked By: crushervx

||

Answers:

If you want the system to be non-blocking then neither Flask or Django are going to natively provide the support you are looking for. You should probably check out Twisted since its the most mature python project for non-blocking IO: http://twistedmatrix.com/trac/

It provides a solid set of API’s for socket-based servers. If you need to integrate with an “regular” webapp, your best bet would be Django since I don’t believe anyone has done a Twisted-Flask integration (I could be wrong, just haven’t seen it). Here’s a link explaining how to setup Django and Twisted in the same environment: http://dreid.org/2009/03/twisted-django-it-wont-burn-down-your.html/

Note: no system daemon required 😉

Answered By: Shakakai

I recommend Eventlet for event based actions with open-socket.

The other options in python for handling twitter real-time api are twisted and tornado.

Answered By: lprsd
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.