Steve,
Sadly I don't think that is sufficient. The "sys" module (aka PySystemState) exists as a ThreadLocal that the jython modules written in java access through Py.getSystemState(). BTW this turns out to be a real pain in the neck when you use a thread pool to execute code for different PythonInterpreters (it requires me to track the PySystemState that should be used for each PythonInterpreter and call Py.setSystemState() with the correct PySystemState before invoking any of my python code).

I don't think there is a way via Py.java to clear the thread state (happy to be corrected). For my use case I ended up not bothering to throw away the PythonInterpreter and attempt to (with some shenanigans related to import hooks) delete and reload modules that have changed. I also however would prefer that I could just call cleanup() and remove all references and that would be it.

Even the (possibly overkill) approach of loading each PythonInterpreter into it's own ClassLoader probably won't work/will leak memory at the moment due to memory leaks related to subclassing Thread (c.f. https://bitbucket.org/jython/jython/pull-request/19/pysystemstateclosershutdowncloser-use and http://bugs.jython.org/issue2127).

Does anyone else have any suggestions?

Cheers
Indra

On 10 May 2014 17:01, Steve Yegge <steve.yegge@gmail.com> wrote:
I create PythonInterpreter instances on demand when admins log into my system.  When they leave I'd like to clean up their interpreter instance.

Do I just call cleanup() and then remove any references to it?  What exactly does PySystemState.callExitFunc do?  Is it just a customization hook that I can safely assume is null if I didn't set it?

------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
&#149; 3 signs your SCM is hindering your productivity
&#149; Requirements for releasing software faster
&#149; Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users




--
Indra Talip