« Return to Thread: problem with jython and threads

problem with jython and threads

by ag356 :: Rate this Message:

Reply to Author | View in Thread

Hi. Can anyone tell me why the following does not work?

== 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.

Any help would be greatly appreciated!

 « Return to Thread: problem with jython and threads