Title: When running multiple engines in different threads, the last registered writer is in use for all script executions.
Type: crash Severity: urgent
Components: Core Versions: Jython 2.7
Milestone: Jython 2.7.1
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: zyasoft Nosy List: darjus, flegall, zyasoft
Priority: low Keywords:

Created on 2014-05-23.08:51:50 by flegall, last changed 2016-01-19.18:35:20 by zyasoft.

File name Uploaded Description Edit Remove flegall, 2014-05-23.08:51:49 Testcase reproducing the problem.
msg8571 (view) Author: Florent Le Gall (flegall) Date: 2014-05-23.08:51:49
When running multiple engines in different threads, the last registered writer is in use for all script executions.
msg8807 (view) Author: Jim Baker (zyasoft) Date: 2014-06-23.18:09:47
JSR 223 issue
msg8830 (view) Author: Jim Baker (zyasoft) Date: 2014-06-28.03:19:18
The problem here is that the PySystemState, via PythonInterpreter, is shared across engines, which is what controls the writer output. Need to possibly reconsider this sharing setup, which is managed by PythonInterpreter.threadLocalStateInterpreter.
msg9090 (view) Author: Jim Baker (zyasoft) Date: 2014-10-06.03:12:48
2.7.1 or later
msg10603 (view) Author: Jim Baker (zyasoft) Date: 2016-01-07.05:58:43
Florent, I finally had a chance to go through JSR 223 support today. The change is trivial:

    [junit] Running org.python.indexer.TestBase
    [junit] Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.376 sec
    [junit] Running org.python.jsr223.ScriptEngineIOTest
diff -r e1ae43e28fbf src/org/python/util/
--- a/src/org/python/util/        Wed Jan 06 22:36:07 2016 -0700
+++ b/src/org/python/util/        Wed Jan 06 22:55:58 2016 -0700
@@ -78,7 +78,7 @@
      * @param dict a Python mapping object (e.g., a dictionary) for use as the default namespace
     public static PythonInterpreter threadLocalStateInterpreter(PyObject dict) {
-        return new PythonInterpreter(dict, null, true);
+        return new PythonInterpreter(dict, new PySystemState(), true);


So I'm going to apply it now because the change makes sense: we should isolate each engine with its own PySystemState. Beta 3 should be a good chance to prove  whether this is truly the case or not.

I would like to add your test to our test suite, so if you could submit a contributor agreement (, I will do add accordingly.

Sorry this has taken so long!
msg10604 (view) Author: Jim Baker (zyasoft) Date: 2016-01-07.06:15:25
Fixed as of
msg10607 (view) Author: Darjus Loktevic (darjus) Date: 2016-01-08.02:01:11
Unfortunately Jim's fix is breaking regrtest pretty badly, so I've backed out the change. We'll have to revisit it.
msg10637 (view) Author: Jim Baker (zyasoft) Date: 2016-01-12.01:38:31
Darjus didn't back out the change ;) and I did commit my fix to test_jsr223. So back in pending.

It could still be the wrong approach, but beta 3 should shake that out.
Date User Action Args
2016-01-19 18:35:20zyasoftsetstatus: pending -> closed
2016-01-12 01:38:41zyasoftsetstatus: open -> pending
2016-01-12 01:38:36zyasoftsetresolution: accepted -> fixed
2016-01-12 01:38:31zyasoftsetmessages: + msg10637
2016-01-08 02:01:12darjussetstatus: pending -> open
resolution: fixed -> accepted
messages: + msg10607
nosy: + darjus
2016-01-07 06:15:26zyasoftsetstatus: open -> pending
versions: + Jython 2.7, - Jython 2.5
messages: + msg10604
assignee: zyasoft
milestone: Jython 2.7.1
resolution: fixed
2016-01-07 05:58:44zyasoftsetmessages: + msg10603
2014-10-06 03:12:48zyasoftsetpriority: low
messages: + msg9090
2014-06-28 03:19:18zyasoftsetmessages: + msg8830
2014-06-23 18:09:47zyasoftsetnosy: + zyasoft
messages: + msg8807
2014-05-23 08:51:50flegallcreate