有没有办法在特定时间后停止reactor.run()
,f.e 10分钟,通过reactor.stop()
和reactor.callFromThread(reactor.stop)
样品:
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)