我正在制作一个程序,使用 Tweepy 提取实时推文,并通过一个函数运行它。我正在使用 Tweepy Stream 来完成获取推文的任务。然而,我希望的是,在该功能运行时,Tweepy 仍然可以拉取这些实时推文。我相信我需要将 Tweepy 事件监听器线程化,但我不完全确定如何执行此操作。
def doesSomething(s):
#function here
class listener(tweepy.StreamListener):
def on_status(self, status):
doesSomething(status)
stream_listener = listener()
tweepy.Stream(auth = api.auth, listener=stream_listener)
stream.filter(track=["Example"])
最佳答案
您可以使用 async=True 参数在另一个线程中运行流:
myStream.filter(track=['python'], async=True)
参见 http://docs.tweepy.org/en/v3.5.0/streaming_how_to.html获取更多信息。
关于python - 如何线程 Tweepy 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39237420/