Message10287

Author oxmane
Recipients oxmane
Date 2015-09-24.14:26:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1443104774.47.0.660056411014.issue2404@psf.upfronthosting.co.za>
In-reply-to
Content
The following small test reproduces a behavior which seems like a bug to us:

@Test
public void testImport() throws Exception {
    Options.importSite = false;
    PySystemState pySystemState = new PySystemState();
    PythonInterpreter interpreter = new PythonInterpreter(null, pySystemState);
    interpreter.exec("import os");
    assertTrue(interpreter.getSystemState().modules.__contains__(new PyString("os")));
}

Notice that the following 4 alterations make the test pass (3 of them seem rather unrelated):
1. Removing "Options.importSite = false;"
2. Adding "System.gc()" after the initialization of the PythonInterpreter
3. Adding some dummy statement like "interpreter.exec("pass")" after the initialization of the PythonInterpreter
4. Adding "Py.defaultSystemState = pySystemState;" between the PySystemState initialization and the PythonInterpreter initialization

It seems to me that the issue is somehow related to the cachedThreadState in the ThreadStateMapping.
In general it seems that this cache might get purged (due to GC) between the setSystemState() and the Py.exec(...) in the exec method of PythonInterpreter in which case the defaultSystemState will get used (which doesn't seem like the intended behavior).
History
Date User Action Args
2015-09-24 14:26:14oxmanesetrecipients: + oxmane
2015-09-24 14:26:14oxmanesetmessageid: <1443104774.47.0.660056411014.issue2404@psf.upfronthosting.co.za>
2015-09-24 14:26:14oxmanelinkissue2404 messages
2015-09-24 14:26:13oxmanecreate