[Twisted-Python] application

Jp Calderone exarkun at divmod.com
Mon Sep 5 14:14:05 EDT 2005

On Mon, 5 Sep 2005 06:37:29 -0700 (PDT), Antony Kummel <antonykummel at yahoo.com> wrote:
>I am beginning to use twisted.application, mktap and
>twistd in my project, and I have some questions about
>their use:
You may want to start out using TAC files, rather than TAP files.  TAC files are easier to manipulate, which is a plus during development.  TAP files will let you solidify whatever configuration you decide upon and expose it via the `mktap' command line.

>1. It seems that mktap is aimed primarily to create
>applications containing just one service (since to
>append a service to an application you need a separate
>invocation of mktap). I am thinking to use it mostly
>to combine services and I wonder if I'm
>misunderstanding something or if I should use
>MultiService or what.
>Specifically, I want to have numerous services that
>are (modified) PB client/servers, and when several
>such services are at the same process, I want them all
>to use the same ServerFactory. What I did was to make
>one mktap plugin for the "base server", and several
>plugins for the services themselves. These services
>require that the application also contains a "base
>server", and they bind to it automatically. This
>requires creating an application with only the "base
>server", and then adding to it the different
>subsidiary services. Any ideas on how to do this

Each service appended to a TAP will have a reference to the parent service, which in turn has references to all its children.  By searching this graph, services can find other services that have been configured independently.  A good way to do this is usually by interface.

>2. Tap conventions: it is not very clear how to make
>the best use of mktap in terms of code organization.
>It seems that to make plugins I need to have a
>twisted/plugins folder in my application's root
>directory. In twisted, this folder contains files
>named twisted_*.py, I'm not sure why this naming
>convention. The files in this directory point to tap
>construction modules. These modules seem to be either
>in twisted/tap or in twisted/*something*, in which
>case they are called either tap.py or
>*something*_tap.py. Additionally, the services these
>modules use come from a variety of places in which I
>couldn't find coherence.
>So, my question is, where should I put the mktap
>plugins, the tap construction modules, and the service
>implementations so that it makes sense? Am I missing

For mktap to find your TAP plugin, it must be in twisted/plugins/.  Beyond that, Twisted doesn't care how you organize things.  As a convention, Twisted uses the twisted_ prefix so as to reduce the chance of colliding with other plugins.  If you want to be nice, you should probably adopt a similar prefix for your plugins.

The modules implementing the TAP plugins can go anywhere importable.  If it helps you decide at all, the twisted/tap/ package is generally considered to have been a mistake, and those modules have been gradually moving out to twisted/project/tap.py files.

>2. I understand that application is meant to hold the
>services' configuration. However, there are many kinds
>of configurations, and I'm struggling to make a
>distinction between options that are suitable for the
>mktap command line, for xml-serialized applications,
>and for other mechanisms, such as a human-readable
>configuration file suitable for an innocent end-user.
>For example, an ini file could be used to specify the
>skin of a GUI application, and debugging options, but
>what is more suitable for the mktap command line?
>Maybe only options that somehow affect the basic
>"type" of the service?

This is a pretty broad question.  I don't know that I have any particular insight into it.  Pretty much every program, whether it uses Twisted or Python or not, has to make a decision here.


More information about the Twisted-Python mailing list