虽然我正在检查反应堆是否已在运行,但是出现ReactorNotRestartable错误

问题描述 投票:1回答:2

码:

def hook(ui, repo, hooktype, node=None, source=None, **kwargs):

    from buildbot.clients import sendchange
    from twisted.internet import defer, reactor

    for master in masters:
        s = sendchange.Sender(master, auth=(username, password))
        d = defer.Deferred()
        reactor.callLater(0, d.callback, None)

        for rev in range(start, end):
            # some code here
            d.addCallback(dummy, "calling dummy")

    def _printSuccess(res):
        pass

    def _printFailure(why):
        pass

    d.addCallbacks(_printSuccess, _printFailure)
    d.addBoth(lambda _: reactor.stop())
    try:
        logger.info("before starting reactor")
        if not reactor.running:
            reactor.run()
            logger.info("after reactor.run")
        else:
            logger.info("reactor is already running")

    except Exception as e:
        logger.info("in exception")
        logger.exception("exception occurred")
        if reactor.running:
            reactor.stop()


def dummy(content):
    with open("/home/rhodecode/hg_buildbot_hooks/dummy.txt", "w") as f:
        f.write("dummy" + "\n")
        f.write("{}".format(content))

错误:

File "/home/rhodecode/hg_buildbot_hooks/hooks.py", line 291, in hook
    reactor.run()
File "/home/rhodecode/buildbot_venv/lib/python2.7/site-packages/twisted/internet/base.py", line 1266, in run
    self.startRunning(installSignalHandlers=installSignalHandlers)
File "/home/rhodecode/buildbot_venv/lib/python2.7/site-packages/twisted/internet/base.py", line 1246, in startRunning
    ReactorBase.startRunning(self)
File "/home/rhodecode/buildbot_venv/lib/python2.7/site-packages/twisted/internet/base.py", line 754, in startRunning
    raise error.ReactorNotRestartable()
ReactorNotRestartable
twisted twisted.internet
2个回答
0
投票

这是ReactorNotRestartable。也许关键字是可重新启动的。你不能多次启动Twisted反应堆 - 即使你在尝试之间停止它也是如此。

© www.soinside.com 2019 - 2024. All rights reserved.