[Twisted-Python] Plugin startup and shutdown actions

Terry Jones terry at jon.es
Sat Apr 11 13:48:38 EDT 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


More information about the Twisted-Python mailing list