On Sep 1, 2005, at 8:48 PM, Stuart D. Gathman wrote:

From: Anand Chitipothu <strandpyper@gmail.com>
Date: Wed, 31 Aug 2005 13:33:57 +0530
Subject: [Jython-dev] Threadsafe sys.stdout

i am using jython to allow scriptability of some functionality from a  GUI
tool.  I have a requirement to allow user to run multiple scripts at the  
same time and show the output of the script there.
      * Returns output stream for the calling thread.
      * Default output stream is returned if no output stream
      * is set for the calling thread.
      * @see set(Writer)
      * @see setDefaultWriter(Writer)
     private Writer getWriter() {
         Writer out = (Writer) threadLocal.get();
         return (out == null) ? defaultWriter : out;
     // }}}
i am wondering can anything be done better than this?
if not why cant we push this to PythonInterpreter.

The problem with the above (in PythonInterpreter) is that the application may
have its own data to store in threadLocal.  To avoid having to cooperate with
apps, I create a map to associate Writer with Thread.  Use the Thread
object as the key to the map.

You can use a different ThreadLocal for that purpose. infact there is a memory leak in your program because you are keeping a reference to the thread and that thread will never be garbage collected.