Best Way to launch an asynchronous function in django?
<p>I am using <code>tweepy</code> library to collect tweets from <code>twitter streaming API</code> and store them in an <code>Elasticsearch</code> server. Overall I am writing a simple <code>Django application</code> to display the tweets in real time, over a map. However for that I need the ElasticSearch database to be populated in realtime, constantly by the Django Server i.e it should preferably start doing it as soon as the Django Server is launched. What will be a good way to go about it ?</p>

<p>The calls look as followin:</p>

<pre><code>streamer = tweepy.Stream(twitter_api.auth, listener=stream_listener)
streamer.filter(locations=[-180, -90, 180, 90], languages=['en'], async=True)
</code></pre>

<p>Use <a href="http://www.celeryproject.org/" rel="nofollow">celery</a> along with <a href="https://pypi.python.org/pypi/celery-haystack" rel="nofollow">celery-haystack</a> (hopefully you are already using <a href="http://haystacksearch.org/" rel="nofollow">django-haystack</a> to interact with Elasticsearch). Its not a straight forward solution but with some effort it is the best solution.</p>

python django twitter django-views tweepy