Skip to main content
 首页 » 编程设计

python之当我运行没有选项的 `twistd` 命令时,为什么我的扭曲插件没有出现

2024年10月25日10mengfanrong

这是我的 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 安装了我的库,它可以从任何地方导入

有什么想法吗?

请您参考如下方法:

正如所怀疑的那样,它非常简单:我需要实例化 MyServiceMaker 的实例,因此只需添加 service_maker = MyServiceMaker()脚本底部的修复了这个问题。