Search code examples
pythontwistedtwistd

Why is my twisted plugin not appearing when I run the `twistd` command with no options?


Here is the current state of my twistd plugin, which is located in project_root/twisted/plugins/my_plugin.py:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from zope.interface import implements

from twisted.plugin import IPlugin
from twisted.python.usage import Options
from twisted.application import internet, service

from mylib.io import MyFactory


class Options(Options):
    """Flags and options for the plugin."""

    optParameters = [
        ('sock', 's', '/tmp/io.sock', 'Path to IO socket'),
    ]


class MyServiceMaker(object):
    implements(service.IServiceMaker, IPlugin)

    tapname = "myplugin"
    description = "description for my plugin"
    options = Options

    def makeService(self, options):
        return internet.UNIXServer(options['sock'], MyFactory())
  • There is no __init__.py file in project_root/twisted/plugins/
  • The output of twistd doesn't show my plugin when run from the project's root directory
  • I installed my library via python setup.py develop --user and it is importable from anywhere

Any ideas?


Solution

  • As suspected, it was something very simple: I needed to instantiate an instance of MyServiceMaker, so simply adding service_maker = MyServiceMaker() at the bottom of the script fixes the issue.