为什么运行不带选项的 `twistd` 命令时我的 twisted 插件不出现?

2 投票
1 回答
588 浏览
提问于 2025-05-01 02:13

这是我目前的 twistd 插件的状态,插件文件位于 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())
  • project_root/twisted/plugins/ 目录下没有 __init__.py 文件
  • 当我从项目的根目录运行 twistd 时,输出中没有显示我的插件
  • 我通过 python setup.py develop --user 安装了我的库,现在可以在任何地方导入它

有什么建议吗?

暂无标签

1 个回答

2

果然,问题非常简单:我需要创建一个 MyServiceMaker 的实例,所以只要在脚本的最后加上 service_maker = MyServiceMaker() 就解决了这个问题。

撰写回答