0

我目前正在使用twitty-twister将实时 Twitter 消息流式传输到一个长时间运行的应用程序中,但是有时我需要重新启动流来更改跟踪参数。是否可以使用此库将此流与 Twitter 断开连接?

4

1 回答 1

0

在对这个问题进行了一些研究之后,我发现不可能“关闭”Twitter 流。

解决方案是使用以下命令在自己的进程中运行 Twitty Twister 脚本reactor.spawnProcess

# spawnProcess requires you to implement a ProcessProtocol
class TwitterProcess(protocol.ProcessProtocol):
    def outReceived(self, data):
        print("TWITTER: ", data)

    def errReceived(self, data):
        print("TWITTER ERR: ", data)

    def processEnded(self, reason):
        print("twitter process ended.")

# later on...

args = ["python", "twitter_stream.py"] # add other args here if necessary
pp = TwitterProcess()
feedProcess = reactor.spawnProcess(pp, "python", args)

然后,如果您想关闭该进程:

feedProcess.signalProcess("TERM")
于 2012-06-05T14:00:23.880 回答