How do you you run a Twisted application via Python (instead of via Twisted)?

后端 未结 6 2007
春和景丽
春和景丽 2020-12-24 08:48

I am working my way through learning Twisted, and have stumbled across something I\'m not sure I\'m terribly fond of - the \"Twisted Command Prompt\". I am fiddling around

6条回答
  •  无人及你
    2020-12-24 09:38

    I don't know if it's the best way to do this but what I do is instead of:

    application = service.Application("chatserver")
    internet.TCPServer(1025, factory).setServiceParent(application)
    

    you can do:

    from twisted.internet import reactor
    reactor.listenTCP(1025, factory)
    reactor.run()
    

    Sumarized if you want to have the two options (twistd and python):

    if __name__ == '__main__':
        from twisted.internet import reactor
        reactor.listenTCP(1025, factory)
        reactor.run()
    else:
        application = service.Application("chatserver")
        internet.TCPServer(1025, factory).setServiceParent(application)
    

    Hope it helps!

提交回复
热议问题