[Pythonmac-SIG] threads in OSX IDLE

Tony Lownds tony@lownds.com
Mon, 8 Jul 2002 15:47:43 -0700


At 10:02 AM +0200 7/5/02, Jack Jansen wrote:
>
>Tk is deinitely not threadsafe. At least, it wasn't the last time I 
>examined it. So this may well be your problem.

Tcl/Tk 8.4 has threading that can be turned off, and Aqua Tk is by 
default threaded as well. In fact it needs thread local storage to 
work. I don't know if 8.3 had threading or not.

When Tk wasn't thread safe, Tkinter added a lock around calls to Tk. 
Now that Tk is threaded, this lock isn't enough: Python creates a 
Python thread object with an OS level thread underneath it, but Tk 
doesn't get a chance to initialize it's thread local storage for that 
OS level thread.

So Tkinter should probably get fixed.

>Maybe you should ask the Idle folks (there's a couple of people 
>working on it) how feasible it is to create a threadsafe Idle.

The idlefork project on sourceforge is where the action is. They have 
an IDLE that runs the python code in a separate process, and 
transmits stdin/stdout/stderr over sockets. So for Jeff's specific 
problem (printing from multiple threads) the idlefork stuff is 
already fixed!

At 4:05 PM +0200 7/8/02, Jack Jansen wrote:
>On Monday, July 8, 2002, at 03:56 , Jeff Senn wrote:
>>Alternatively, (and I apologize for my lack of MacOS X Python knowlege)
>>is there some way to run python with stdio to/from a terminal and still
>>be able to use the TK Framework?
>
>Build a framework Python, build the Python.app with 
>Mac/OSX/Makefile, and run "make installunixprograms" there too. Now 
>run your script from Terminal with "pythonw mytkscript.py".
>
>Haven't tried it for Tkinter, but it works for Cocoa and Carbon so 
>it should be fine for Tkinter too.

This works fine for Tkinter. Here's a neat trick: copy that pythonw 
script somewhere and name it pythonw.command - double clicking it in 
the finder will open a terminal window for you.

Another way to work around this can't print from threads issue is 
doing print >> opened_file in your script and then tail -F file in 
another window.

-Tony