Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 365
crushervx Avatar asked Feb 14 '11 10:02

crushervx


2 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 ;)

like image 196
Shakakai Avatar answered Sep 28 '22 03:09

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.

like image 30
lprsd Avatar answered Sep 28 '22 02:09

lprsd