On Jan 15, 2008 9:46 AM, Raghuram Devarakonda <draghuram@...> wrote:
> I ran into the error:
>
> "LookupError: no codec search functions registered: can't find encoding"
>
> using jython 2.1 on windows and with little debugging, I found that
> the problem exists with latest trunk as well. The following code
> demonstrates the issue:
>
> -------------
> import java
> import time
>
> class codec_test(java.lang.Runnable):
> def run(self):
> print "test string".encode('utf-8')
>
> th1 = java.lang.Thread(codec_test())
> th2 = java.lang.Thread(codec_test())
> th1.start()
> # time.sleep(1)
> th2.start()
> -------------
>
> My tests are on SuSe 10 using "Jython 2.2 on java1.6.0_02". When run
> as is, I consistently get the following result:
>
> -------------
> Exception in thread "Thread-1" Traceback (innermost last):
> File "codec_test.py", line 15, in run
> LookupError: no codec search functions registered: can't find encoding
> test string
> -------------
>
> If "time.sleep(1)" line is uncommented, the result is:
>
> -------------
> test string
> test string
> -------------
>
> The problem is in codecs.java's lookup() and registry_init(). When two
> threads call lookup() simultaneously, one thread's registry_init()
> returns even when it is not done importing all the codecs. What does
> one think of synchronizing the method "registry_init()"? The above
> test consistently passes with that change.
Sounds reasonable to me. Committed to trunk in r4059 and backported
to Release_2_2maint in r4060 so this will be in 2.2.2.
Charlie
|