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

Don't confuse "Twisted" with "twistd". When you use "twistd", you are running the program with Python. "twistd" is a Python program that, among other things, can load an application from a .tac file (as you're doing here).

The "Twisted Command Prompt" is a Twisted installer-provided convenience to help out people on Windows. All it is doing is setting %PATH% to include the directory containing the "twistd" program. You could run twistd from a normal command prompt if you set your %PATH% properly or invoke it with the full path.

If you're not satisfied with this, perhaps you can expand your question to include a description of the problems you're having when using "twistd".


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!