[Twisted-Python] How do I run a twisted server directly

Alexander May alex-news at comcast.net
Fri May 14 22:02:45 EDT 2004

I've use pythonwin for a while and I'm giving Komodo try right now.  I'll
try Python.NET soon too.

I cribbed from twistw and did this:

if '__main__' == __name__:
    from twisted.application import app
    import sys
    class ServerOptions(app.ServerOptions):
        optFlags = [['nodaemon','y',  "(for backwards compatability)."]]
    app.startApplication(application, 0)
    app.runReactorWithLogging(ServerOptions(), sys.stdout, sys.stderr)

Which seems to work.  I can start my application from the debugger and hit
breakpoints, etc.  

Presumably I've committed all sort of horrors writing this code.  Please
feel free to enlighten me to the error of my ways.  Also, I'm curious what
is the function of the following line of code (marked with a *) is which I
saw in twistw:

def runApp(config):
    passphrase = app.getPassphrase(config['encrypted'])
    application = app.getApplication(config, passphrase)
    oldstdout = sys.stdout
    oldstderr = sys.stderr
    app.startApplication(application, not config['no_save'])
*   app.startApplication(internet.TimerService(0.1, lambda:None), 0)
    app.runReactorWithLogging(config, oldstdout, oldstderr)
    log.msg("Server Shut Down.")

*    do nothing frequently?



-----Original Message-----
From: twisted-python-bounces at twistedmatrix.com
[mailto:twisted-python-bounces at twistedmatrix.com] On Behalf Of Robert Church
Sent: Friday, May 14, 2004 9:43 PM
To: Twisted discussion stuff
Subject: Re: [Twisted-Python] How do I run a twisted server directly

Alexander May wrote:
> Oops, thanks.  Any hope debugging in my IDE instead of pdb?

What's your IDE?

Twisted-Python mailing list
Twisted-Python at twistedmatrix.com

More information about the Twisted-Python mailing list