特定时间后的扭曲反应器

Twisted reactor after specific period of time

有没有办法在特定时间 f.e 10 分钟后通过 reactor.stop()reactor.callFromThread(reactor.stop)

停止 reactor.run()

样本:

import sys
from twisted.python import log
from twisted.internet import reactor, task
from twisted.internet.defer import Deferred, DeferredList
from autobahn.twisted.websocket import connectWS
from protocol import WampClientFactory, WampClientProtocol

class SMSManagementProtocol(WampClientProtocol):
    def showEvent(self, topicUri, result):
        print "EVENT:", topicUri,result
    def onSessionOpen(self):
        self.prefix("event", "http://test.tv/subscribe_public")
        self.subscribe('psevent:on_sms_delivered', self.showEvent)
        self.publish("event:send_sms", {'sms_text':'test','phone_number':29999999,'user_name':'test'})

if __name__ == '__main__':
    sms_factory = WampClientFactory("ws://xx.xx.xxx.x:xxxx", debugWamp = True)
    sms_factory.protocol = SMSManagementProtocol
    connectWS(sms_factory)
    reactor.run()

这样可以停止反应堆吗?

def check_stop_flag():
if reactor.run(600):
    reactor.stop()
lc = task.LoopingCall(check_stop_flag)
lc.start(600)

您可以在 reactor.callLater:

的时间延迟后安排任何函数调用
reactor.callLater(60 * 10, reactor.stop)