[Twisted-Python] mktap/twistd in a Windows service

Jean-Paul Calderone exarkun at divmod.com
Sun Nov 4 16:23:52 EST 2007


On Sun, 04 Nov 2007 17:52:35 +0000, Paul Moore <pf_moore at yahoo.co.uk> wrote:
>I know this is a FAQ, but it's not in the FAQ list and I've had no luck 
>finding a good answer via web or list searches (Windows is a lousy search 
>term, and service isn't much use in a Twisted context...)
>
>I want to run a tiny non-authoritative DNS server on my PC. I've never done 
>this before, but twisted names looks ideal. The documentation 
>(http://twistedmatrix.com/projects/names/documentation/howto/names.html) 
>says I just need to do
>
>     mktap dns --recursive --cache
>     twistd -f dns.tap
>

In recent versions of Twisted, you can simplify the above to this:

    twistd dns --recursive --cache

This skips the tap phase: it creates the same application mktap would have
created, but instead of putting it in the tap file, it just runs it.

>and indeed this works fine. I seem to recall some time ago seeing postings 
>to the effect that tap format files were out of favour, but I don't follow 
>the twisted list much, so I don't know if this is still true. Nevertheless, 
>it works so who cares?

Quite so.

>
>However, I want to run this as a Windows service. Ideally, twistd would have 
>a --install-service flag or something, but it doesn't so I went looking, and 
>found postings covering tap2ntsvc which creates services from tap files, but 
>it seems to have been replaced by ntsvc, which only handles .tac files :-(

It would be very excellent if twistd had a --install-service flag.  There is
a relatively minimal level of interest in Windows-specific functionality
among the currently active Twisted developers, though.  This means that it
isn't very likely that any of us will undertake to add this feature.

That doesn't mean that we'll never implement it, nor that we wouldn't accept
a patch which implements it from someone else who is more interested in it
than we are.  If someone provides the functionality, with unit tests, then
we'll gladly incorporate and maintain it.  I'm not sure if you would be
interested in doing this work or not;  I'm directing this as much at you as
at all of the other users of Twisted on Windows who I know are out there and
mostly remain silently.

>
>I get the impression that the idea is that .tac files are easy to create by 
>hand, but as I know *nothing* about twisted names (and don't really want to 
>- all I want is to run a DNS server!) it's not as easy as it might be...

They are, more or less, although they are harder to make than tap files. ;)

>
>So, can someone tell me:
>
>1. What is the currently favoured form for Twisted application files?

It all depends on the use-case.  For all of the services distributed with
Twisted itself, tap files offer very little over the persistence-free form
of twistd I gave an example of above.  Since tap files contain pickled data,
they have all the problems of pickle (lack of introspectability, problems
with compatibility, security); if these aren't problems, then tap files
might be okay.  On the other hand, many uses of twistd don't actually need
any persistence, so using tap files doesn't actually provide any benefits.

>2. How do I make one for twisted names (the equivalent of the mktap line 
>above) and better still how do I generalise this for any mktap command?

See twisted.names.tap.makeService - this is the function `mktap dns´ is
calling to create the object it will pickle into the tap file.  Your tac
file can call it directly with the desired configuration and add the
resulting service to an application object.  This will give you a tac
which does the same thing as your mktap-produced tap file.  You can
read more about writing tac files here:

  http://twistedmatrix.com/projects/core/documentation/howto/application.html

>3. How do I run it? (twistd, presumably)

As you said below, twistd -noy.

>4. How do I make that file run as a Windows service?
>

I've never used ntsvc, so I can't say if that's right, but presumably
it is at least close.

There isn't any reason that if ntsvc works with tac files it couldn't
also work with tap files, though.  So another solution might be to explore
adding tap file support to ntsvc.  The interface for loading a tac file is
really the same as the interface for loading a tap file, in fact, so I am
slightly surprised ntsvc doesn't work with tap files.

>
>I believe, from what I've found, that the answers are:
>1. .tac
>2. Don't know - not sure there's a generic answer.
>3. twistd -noy
>4. ntsvc
>
>In which case, the documentation really needs to be updated to explain .tac 
>files throughout, instead of mktap. And I need someone to write me a dns.tac 
>file :-(
>
>Ideally, this should be written up as a FAQ or HOWTO somewhere. I'll 
>volunteer to write it up, as long as someone will maintain it - I'm not in a 
>position to do so (I use twisted occasionally, but have no need or desire to 
>follow development versions or discussions on the list). I don't want to 
>bother doing a write-up, if it won't get included in the docs/FAQ and 
>maintained, though...

Anything (accurate, coherent) you want to write up we'd be glad to add to
the Twisted repository and include on the website, in releases, etc.

Jean-Paul




More information about the Twisted-Python mailing list