[Twisted-Python] Windows issues...

Andrew Bennetts andrew-twisted at puzzling.org
Mon Feb 18 19:24:35 EST 2002

On Mon, Feb 18, 2002 at 06:34:33PM -0500, Benjamin Schollnick wrote:
> Folks,
>    I've got some questions, with windows usage of Twisted Matrix...

I use Twisted under Windows, so I may be able to offer some help..

> 1) setup.py install    died....It stopped when it couldn't find "CL.EXE",
> while building
>    something in the twisted.spread.cbanana section...

CL.EXE is a command line program that comes with MS Visual C++...  setup.py
is basically trying to compile a C extension module.  I can send you a
binary for that file if you don't have MS VC++ installed, otherwise run
VCVARS32.BAT and try again. 

> 2) A lot of the files, don't have a .py extension.  (i.e. mktap, twistd,
> etc)
>    This is a major hindrance, because either I have to rename the file, or
>    execute it explicitly "python mktap ....etc....".  I have windows set to
> run
>    the .py files via python automatically.

This is easily fixed with short bash script, but I agree, this is annoyed.

I'd suggest the Twisted developers look at how, e.g. PyChecker or Teud does
it (various scripts get installed in %PYTHONPATH%/scripts/<foo>.bat).

> 3) web.distrib has some issues.  Mainly attempting to use the pwd unit under
> 4) Error checking is extremely light....
> 5) Even after fixing #3, mktap web --static static, isn't working.

I don't use the twisted.web stuff (yet ;), so I can't offer any help here :(

> 6) Under Windows, the default should be -n for twistd, and the PID file
> shouldn't be created.   At least, as it is now.  twistd just "stops", after
> it starts up and drops us back to the command line, and examination shows
> that the program isn't running.  So at least as a workaround, the -n mode
> works....

Yeah, -n uses os.fork, which is not available under Windows.  You probably
need to use NT services instead...

Alternatively, consider using the cygwin version of Python -- it is closer
to the unix version, and so os.fork will work.  Also, it comes with gcc, so
cbanana would compile correctly.  Unfortunately, I don't think it can
interoperate with the Win32 extensions (at least, not that I know of).

> I guest a better question is, has twistedmatrix been tested under Windows?
> It really seems to be unix centric in it's programming...

It basically works.  The other problem to watch out for is that
Protocol.connectionFailed won't trigger unless you specify a timeout for
your tcp.Client, because select works slightly differently on Windows.

Incidentally, I'm not using the twistd stuff *at all* (I don't yet
understand the need for it under Windows, but then I don't even know exactly
what it's meant to do...).  Instead, I'm using this little file:

--- ServerFramework/Service.py ---
import win32serviceutil, win32service

"""Example use of this module:

from ServerFramework.Service import Service, main
import ExampleServer

class ExampleServerService(Service):
    _svc_name_ = "ExampleServerService"
    _svc_display_name_ = "My Example Server Service"
    main = ExampleServer.main

if __name__ == '__main__':

    import twisted
except ImportError:
    print "Twisted Python must be installed to run this service"

class Service(win32serviceutil.ServiceFramework):
    """I am a template service for ServerFramework servers.
    You should subclass me and override the following attributes:
        _svc_name_          -- see win32serviceutil docs
        _svc_display_name_  -- see win32serviceutil docs
        main                -- function that starts your server
    You can also override:
        logFile             -- filename for where debug messages will be saved
                               (default: c:/<_svc_name_>.log)
    _svc_name_ = "UnnamedServer"
    _svc_display_name_ = "My UNNAMED Server"
    main = None
    logFile = None

    def __init__(self, *args):
        win32serviceutil.ServiceFramework.__init__(self, *args)
        if not self.logFile:
            self.logFile = 'c:/%s.log' % (self._svc_name_,)

    def SvcDoRun(self):
        from twisted.python.log import startLogging
        # Call main, note that it is not a method of this class, so we use
        # self.main.im_func() instead of self.main().

    def SvcStop(self):
        from twisted.internet.main import shutDown

def main(svc):
if __name__ == '__main__':
    print "This is a library module, and should not be executed."

It basically wraps up the functionality of the win32serviceutil in a
convenient way for Twisted servers.  Once you've used it as shown in the
example, just run it from the commandline -- it's self explantory (it uses
Mark Hammond's win32serviceutil.HandleCommandLine function to let you
install the service).  I'm not sure if the self.main.im_func trick will work
on older Pythons; I use 2.2.

I hope this is of some use to you.


More information about the Twisted-Python mailing list