【问题标题】:Why is my twisted plugin not appearing when I run the `twistd` command with no options?为什么我在没有选项的情况下运行 `twistd` 命令时没有出现我的扭曲插件?
【发布时间】:2014-11-02 01:50:28
【问题描述】:

这是我的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/ 中有 no __init__.py 文件
  • twistd 从项目根目录运行时,输出不显示我的插件
  • 我通过python setup.py develop --user 安装了我的库,它可以从任何地方导入

有什么想法吗?

【问题讨论】:

    标签: python twisted twistd


    【解决方案1】:

    正如怀疑的那样,这非常很简单:我需要实例化MyServiceMaker 的实例,因此只需在脚本底部添加service_maker = MyServiceMaker() 即可解决问题。

    【讨论】:

    • 我也有同样的问题……但我没有忘记你所做的事情。
    猜你喜欢
    • 2021-07-13
    • 1970-01-01
    • 2019-11-06
    • 1970-01-01
    • 2015-12-14
    • 2011-10-19
    • 2021-12-05
    • 2020-07-10
    相关资源
    最近更新 更多