Skip to content Skip to sidebar Skip to footer

Is It Possible To Stop Twython Streaming At Certain Point Of Time?

I have the codes for twython streaming and it is working. def read_cred(file): in_handle = open(file,'r') cred = {} for ln in in_handle: data = ln.strip('\r\n').split('=')

Solution 1:

As long as the stop button is bound to the rest of the app (I haven't used Django, so I can't provide a simple example) then calling sys.exit() should do the job.

Django might have some other method for terminating a process built into it or some specific examples in its documentation. You should check that to confirm this answer.

Solution 2:

You can use the disconnect() function as described in the documentation of Twython - https://twython.readthedocs.org/en/latest/api.html#twython.TwythonStreamer.disconnect

defon_stop(self, status_code, data):
            self.disconnect()
    defon_start(keywords):
            stream = MyStreamer(cred['consumer_key'], cred['consumer_secret'],
                     cred['access_token_key'], cred['access_token_secret'])
            stream.statuses.filter(track=keywords)

Post a Comment for "Is It Possible To Stop Twython Streaming At Certain Point Of Time?"