Author jsaiz
Recipients jsaiz, zyasoft
Date 2016-08-25.13:26:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
We create PythonInterpreter instances by means of a custom InterpreterFactory.

This class contains the following map:

// Map with hard references to thread states, depending on their interpreter
private static final Map<PythonInterpreter, ThreadState> threadStates = new WeakHashMap<>();

Then the method InterpreterFactory.newInterpreter, before returning the created PythonInterpreter, stores the interpreter in the auxiliary map. Something like:

PySystemState sysState = new PySystemState();
PythonInterpreter pythonInterpreter = new PythonInterpreter(null, sysState);
ThreadState threadState = Py.getThreadState(sysState);
threadStates.put(pythonInterpreter, threadState);

This ensures that the ThreadState of the created PythonInterpreter is not garbage collected during the interpreter's lifetime, with the net effect that the appropriate PySystemState will be used for every interpreter.

This idea might somehow be implemented in the Jython core.
Date User Action Args
2016-08-25 13:26:26jsaizsetmessageid: <>
2016-08-25 13:26:26jsaizsetrecipients: + jsaiz, zyasoft
2016-08-25 13:26:26jsaizlinkissue2505 messages
2016-08-25 13:26:25jsaizcreate