[Twisted-Python] Import TypeError

Jean-Paul Calderone exarkun at divmod.com
Sun Nov 9 08:52:30 EST 2008

On Sat, 8 Nov 2008 22:15:39 -0500, James Joplin <thejayjay at gmail.com> wrote:
>I've been doing some embedded python work and everything has been working
>like a charm thusfar!  Twisted has saved us tons of work, hats off to the
>development team.
>I have been having issues with shutting down twisted completely (I think).
> Even upon executing Py_Finalize or Py_EndInterpreter as necessary upon
>re-entering our browser plugin we hit an exception during twisted import.
>Here is my traceback :
>Traceback (most recent call last):
>  File "<string>", line 1, in <module>
>  File "ourCode.py", line 8, in <module>
>    from twisted.spread import pb
>  File "C:\Python25\lib\site-packages\twisted\spread\pb.py", line 69, in
>    from zope.interface import implements, Interface
>  File "C:\Python25\lib\site-packages\zope\interface\__init__.py", line 58,
>in <module>
>    _wire()
>  File "C:\Python25\lib\site-packages\zope\interface\interface.py", line
>809, in _wire
>    classImplements(Attribute, IAttribute)
>  File "C:\Python25\lib\site-packages\zope\interface\declarations.py", line
>461, in classImplements
>    spec = implementedBy(cls)
>  File "C:\Python25\lib\site-packages\zope\interface\declarations.py", line
>332, in implementedByFallback
>    if isinstance(spec, Implements):
>TypeError: 'NoneType' object is not callable
>Changing the order of imports hasn't seemed to matter, looks to me like
>something in zope init blows up if it's already loaded.
>Is there a safe way to make sure the threads are dead?  To clean imports
>out?  Anything?  I haven't been able to find much documentation to help me
>overcome the problem and I CANNOT forcibly unload our app from browser

Does CPython even support what you're trying to do?  As I recall, while
the interpreter finalization APIs mostly clean things up, they do leak
some resources.  On top of that, application-level finalization semantics
in CPython (that is, what happens to the Python code) are very unfriendly
and not very well defined.  For example, as you see, the globals of every
module are all reset to None, so any code that uses globals will probably

>If the C++ code we are using for startup / shutdown let me know and I will
>post it as well.

I'm not sure, but I don't think the problem you're seeing actually has
anything in particular to do with Twisted or Zope Interface.  I think it's
due to CPython's initialization and finalization behavior.  Can you produce
a similar exception by importing some trivial stand-alone Python code that
uses globals in a similar way?


More information about the Twisted-Python mailing list