[Twisted-Python] twisted.plugin question

glyph at divmod.com glyph at divmod.com
Thu Jun 15 15:08:47 EDT 2006



On Thu, 15 Jun 2006 17:09:26 +0200, Terry Jones <terry at jon.es> wrote:

>sys.path[:0] = ['./twisted/plugins']

This line is unnecessary, and probably wrong.  If you look in twisted/plugins/__init__.py, you will notice that it puts any additional entries on sys.path into its __path__; the fact that "." is already on your sys.path is enough for it to recognize this plugin.

>def displayAllKnownMaterials():
>    for material in getPlugins(IMaterial):
>        displayMaterial(material)

This is going to look for plugins in twisted.plugins, which is probably not what you want.  Did you look under the "alternate plugin packages" section of that document?

>from twisted.plugin import IPlugin
>from plugin import IMaterial

There is some vagueness in naming here.  Depending on your working directory (etc) twisted.plugin might be picked up as plugin.  You probably want to change the name of your example module to something unique.

>When I run plugin.py, I get the error:

My analysis of this is the same as JP's; however, generally the file you run with 'python' should look something like this:

    from myapp import main
    main()

Python has the unfortunate habit of creating a special module called "__main__" and putting the code from the file it is passed onto the commandline into that module, rather than into the location where it would go if you imported it; having two copies of your "plugin" module in memory at once (the imported one, and the __main__ one) is probably causing at least some of your problems.





More information about the Twisted-Python mailing list