[Twisted-Python] Import TypeError

James Joplin thejayjay at gmail.com
Sun Nov 9 14:05:32 EST 2008

I believe you are correct.  From what literature and other forms of
documentation I could find online counting on py_finalize() to cleanup
everything for you is not reliable at all.  Static members, globals, and
other "things" may stick around if threads aren't done and who knows what
else.  From what I could gather py_finalize() doesn't even kill child
threads, yikes.
I had done a basic test case with other modules than twisted included and I
was not getting import errors.

I ended up just engineering around the problem and left the
python interpreter running.  I had several python exports that needed to be
visible to c and my scripting language and I just used a data structure to
tie the callable python functions to what I exported them as.  Upon
re-entering the dll I just check to see if we have loaded python and if we
have just re-populate my scripting language name space.  Works like a charm.

Thanks for the help!  I didn't think this was your fault to begin with but
it was nice to have some re-assurance.



On Sun, Nov 9, 2008 at 8:52 AM, Jean-Paul Calderone <exarkun at divmod.com>wrote:

> 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
>> <module>
>>   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
>> memory.
> 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
> break.
>> 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?
> Jean-Paul
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20081109/72f23ef8/attachment.htm 

More information about the Twisted-Python mailing list