实现多线程 - Tweepy

Implementing multithreading - Tweepy

是否可以在 Tweepy 流中使用多线程?我使用的代码无法正常工作(每次刷新页面时都不会显示数据)。

提前致谢,问候。

import tweepy

auth = tweepy.OAuthHandler(myaplkey, myappsecret)
auth.set_access_token(mytokenkey, mytokensecret)

api = tweepy.API(auth)

stream_listener = tweepy.StreamListener()
stream = tweepy.Stream(auth=api.auth, listener=stream_listener)
stream.filter(track=["mysearch"], a_sync=True)
stream.filter(track=settings.TRACK_TERMS)

对于 Tweepy v3.10,您可以使用 Stream.filteris_async 参数。
参见 https://tweepy.readthedocs.io/en/stable/streaming_how_to.html#async-streaming

在master分支的开发版本中,这已经改为threaded
参见 https://tweepy.readthedocs.io/en/latest/streaming.html#threading

您还需要继承 StreamListener,因为默认情况下,它不输出任何内容。
有关详细信息,请参阅 Streaming With Tweepy section of the documentation for v3.10