为什么reactor.stop(从twisted.internet导入)一次也不能工作?

2024-09-24 00:25:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试了以下实现,一个是'reactor.stop()',另一个是'reactor.stop':

    reactor.listenTCP(
        host_port, server.Site(PageFactory())
        ).stopListening()
    reactor.callFromThread(reactor.stop())
    while reactor.running:
        print("running")
        time.sleep(0.1)
    if not reactor.running:
        print("STOPPED!!!!!")

上面在“reactor.stop()”行引发异常: “第1016行,在callFromThread中 断言可调用(f),“%s不可调用”%(f,) AssertionError:None是不可调用的“ 尽管我使用了'from twisted.internet import reactor',而且许多人似乎使用reactor.stop()。所以不能打印“running”或“STOPPED!!!”

    reactor.listenTCP(
        host_port, server.Site(PageFactory())
        ).stopListening()
    reactor.callFromThread(reactor.stop)
    while reactor.running:
        print("running")
        time.sleep(0.1)
    if not reactor.running:
        print("STOPPED!!!!!")

上面无休止的打印“运行”,所以反应堆永远不会停止


Tags: hostservertimeportsiterunningstopreactor