I believe you are correct. &nbsp;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. &nbsp;Static members, globals, and other &quot;things&quot; may stick around if threads aren&#39;t done and who knows what else. &nbsp;From what I could gather py_finalize() doesn&#39;t even kill child threads, yikes.<div>
<br></div><div>I had done a basic test case with other modules than twisted included and I was not getting import errors.</div><div><br></div><div>I ended up just engineering around the problem and left the python&nbsp;interpreter&nbsp;running. &nbsp;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. &nbsp;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&nbsp;name space. &nbsp;Works like a charm.</div>
<div><br></div><div><br></div><div>Thanks for the help! &nbsp;I didn&#39;t think this was your fault to begin with but it was nice to have some re-assurance.</div><div><br></div><div><br></div><div>Regards,</div><div><br></div>
<div>James</div><div><br><br><div class="gmail_quote">On Sun, Nov 9, 2008 at 8:52 AM, Jean-Paul Calderone <span dir="ltr">&lt;<a href="mailto:exarkun@divmod.com">exarkun@divmod.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="Wj3C7c">On Sat, 8 Nov 2008 22:15:39 -0500, James Joplin &lt;<a href="mailto:thejayjay@gmail.com" target="_blank">thejayjay@gmail.com</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I&#39;ve been doing some embedded python work and everything has been working<br>
like a charm thusfar! &nbsp;Twisted has saved us tons of work, hats off to the<br>
development team.<br>
<br>
I have been having issues with shutting down twisted completely (I think).<br>
Even upon executing Py_Finalize or Py_EndInterpreter as necessary upon<br>
re-entering our browser plugin we hit an exception during twisted import.<br>
<br>
<br>
Here is my traceback :<br>
<br>
Traceback (most recent call last):<br>
&nbsp;File &quot;&lt;string&gt;&quot;, line 1, in &lt;module&gt;<br>
&nbsp;File &quot;ourCode.py&quot;, line 8, in &lt;module&gt;<br>
 &nbsp; from twisted.spread import pb<br>
&nbsp;File &quot;C:\Python25\lib\site-packages\twisted\spread\pb.py&quot;, line 69, in<br>
&lt;module&gt;<br>
 &nbsp; from zope.interface import implements, Interface<br>
&nbsp;File &quot;C:\Python25\lib\site-packages\zope\interface\__init__.py&quot;, line 58,<br>
in &lt;module&gt;<br>
 &nbsp; _wire()<br>
&nbsp;File &quot;C:\Python25\lib\site-packages\zope\interface\interface.py&quot;, line<br>
809, in _wire<br>
 &nbsp; classImplements(Attribute, IAttribute)<br>
&nbsp;File &quot;C:\Python25\lib\site-packages\zope\interface\declarations.py&quot;, line<br>
461, in classImplements<br>
 &nbsp; spec = implementedBy(cls)<br>
&nbsp;File &quot;C:\Python25\lib\site-packages\zope\interface\declarations.py&quot;, line<br>
332, in implementedByFallback<br>
 &nbsp; if isinstance(spec, Implements):<br>
TypeError: &#39;NoneType&#39; object is not callable<br>
<br>
<br>
Changing the order of imports hasn&#39;t seemed to matter, looks to me like<br>
something in zope init blows up if it&#39;s already loaded.<br>
<br>
Is there a safe way to make sure the threads are dead? &nbsp;To clean imports<br>
out? &nbsp;Anything? &nbsp;I haven&#39;t been able to find much documentation to help me<br>
overcome the problem and I CANNOT forcibly unload our app from browser<br>
memory.<br>
</blockquote>
<br></div></div>
Does CPython even support what you&#39;re trying to do? &nbsp;As I recall, while<br>
the interpreter finalization APIs mostly clean things up, they do leak<br>
some resources. &nbsp;On top of that, application-level finalization semantics<br>
in CPython (that is, what happens to the Python code) are very unfriendly<br>
and not very well defined. &nbsp;For example, as you see, the globals of every<br>
module are all reset to None, so any code that uses globals will probably<br>
break.<div class="Ih2E3d"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
If the C++ code we are using for startup / shutdown let me know and I will<br>
post it as well.<br>
<br>
</blockquote>
<br></div>
I&#39;m not sure, but I don&#39;t think the problem you&#39;re seeing actually has<br>
anything in particular to do with Twisted or Zope Interface. &nbsp;I think it&#39;s<br>
due to CPython&#39;s initialization and finalization behavior. &nbsp;Can you produce<br>
a similar exception by importing some trivial stand-alone Python code that<br>
uses globals in a similar way?<br>
<br>
Jean-Paul<br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</blockquote></div><br></div>