Issue1169

classification
Title: creating codecs from multiple threads can lead to incorrect initialization
Type: Severity: normal
Components: Core Versions: 2.2.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: cgroves, draghuram, pjenvey
Priority: low Keywords:

Created on 2008-11-09.18:40:57 by cgroves, last changed 2009-06-21.21:51:20 by pjenvey.

Messages
msg3768 (view) Author: Charlie Groves (cgroves) Date: 2008-11-09.18:40:56
From
http://www.nabble.com/problem-with-jython-and-threads-to20371245.html#a20371245:

== Begin

import org.python.util.PythonInterpreter;

public class test {

 public static void main(String[] args) throws Exception {
   for (int i = 0; i < 10; i++) {
     new Thread () {
       public void run () {
         String code = "s = \"Hello " +
           Thread.currentThread().getName() +
           "\"\nb = unicode(s,\"utf-8\")\nprint b\n";
         System.out.println("code:\n"+code);
         PythonInterpreter interp = new PythonInterpreter();
         interp.exec(code);
       }
     }.start();
   }
 }

}

== End

I get "LookupError: no codec search functions registered: can't find
encoding" for usually all but one of the threads. Sometimes two or three of
them work.

If I add "import encodings" to the beginning of the script then it works.
msg3771 (view) Author: Raghuram Devarakonda (draghuram) Date: 2008-11-10.14:04:27
Charlie, Isn't this same problem as I reported earlier?

http://www.nabble.com/thread-safety-of-codecs.java%3Aregistry_init%28%29-to14847747.html#a14847747

I remember that you fixed it at that time. The following is the relevant
check-in comment I found for codecs.java

-----
r4059 | cgroves | 2008-01-19 17:52:16 -0500 (Sat, 19 Jan 2008) | 1 line

synchronize around registry_init so if two threads start up and use
codecs immediately, they both get a valid list of encodings
-----
msg3781 (view) Author: Charlie Groves (cgroves) Date: 2008-11-14.17:56:03
It's something like that, but it looks like we didn't manage to
synchronize everything that needed to be synchronized.  I haven't had a
chance to look at what's getting out of whack.
msg3815 (view) Author: Philip Jenvey (pjenvey) Date: 2008-11-23.02:14:34
This must be a 2.2 bug -- can't reproduce it on 2.5 with even 30 threads. 
I sent the originator an email, asking if it was
msg4834 (view) Author: Philip Jenvey (pjenvey) Date: 2009-06-21.21:51:19
No response from the originator: this must have just been a 2.2 bug, 
resolved in 2.5
History
Date User Action Args
2009-06-21 21:51:20pjenveysetstatus: open -> closed
resolution: fixed
messages: + msg4834
2009-03-14 02:28:22fwierzbickisetpriority: low
versions: + 2.2.2
2008-11-23 02:14:34pjenveysetnosy: + pjenvey
messages: + msg3815
2008-11-14 17:56:03cgrovessetmessages: + msg3781
2008-11-10 14:04:27draghuramsetnosy: + draghuram
messages: + msg3771
2008-11-09 18:40:57cgrovescreate