擅长:python、mysql、java
<p>当我查看流类构造函数并找到(async)参数并将其设置为true时,我解决了这个问题,下面是我的代码:</p>
<pre><code>twitterStream=Stream(OAuthObject,listenerFunction())
while True:
if twitterStream.running is True:
twitterStream.disconnect()
keywords=getKeywordsFromDb() # return string of keywords seaprated by comma
if keywords=='':
print 'no keywords to listen to'
else:
twitterStream.filter(track=[keywords],async=True) # Open the stream to work on asynchronously on a different thread
time.sleep(3600) # sleep for one hour
</code></pre>