0

I'm using the twitter python package in pip to access the TwitterStream class.

The code for this looks somewhat like this:

twitter_stream = TwitterStream(auth=UserPassAuth('joe', 'joespassword')) 
iterator = twitter_stream.statuses.sample()

for tweet in iterator:
    # ...do something with this tweet...

I only want the for loop to run for a certain amount of time (say, one minute), so to do this, I inserted a time check in the for loop. My problem though is that if the tweets aren't getting pushed frequently enough, then the body of the for loop never executes and the code essentially hangs until the next tweet comes in.

Does anyone have any ideas on how to get around this? The block param from the docs doesn't return often enough when set to false.

Thanks

khalid13
  • 2,767
  • 2
  • 30
  • 48

1 Answers1

0

If you look at https://github.com/sixohsix/twitter/blob/master/twitter/stream.py you see that the init method of the TwitterStream class accepts a block parameter

Christian Thieme
  • 1,114
  • 6
  • 6
  • Yes, but the block param from the docs doesn't return often enough for my purposes when set to false. I was wondering if there was a way to set the for loop to return automatically when the time for it to run was over. – khalid13 May 01 '13 at 21:25