[Twisted-Python] Plugin startup and shutdown actions

Terry Jones terry at jon.es
Sat Apr 11 11:48:38 MDT 2009


Hi Luper

>>>>> "luper" == luper rouch <luper.rouch at gmail.com> writes:

luper> I have a last question, I put my plugins in a 'twisted/plugins'
luper> subfolder of my project, and running them from the command line
luper> works fine. How can I invoke them in unit tests (I need to be able
luper> to start and stop them), since the plugin files are not in a
luper> package?

I suspect some will answer "Uh, you probably shouldn't be doing that"...

But something like this will work:

    from twisted.plugin import getPlugins
    from twisted.application.service import IServiceMaker

    def getPlugin(name):
        for plugin in getPlugins(IServiceMaker):
            if hasattr(plugin, 'tapname'):
                if plugin.tapname == name:
                    return plugin
        return None

Terry




More information about the Twisted-Python mailing list