[Tkinter-discuss] Help: _tkinter.createfilehandler not supported for threaded Tcl

Jeff Epler jepler at unpythonic.net
Wed Jun 22 14:54:08 CEST 2005


My system is:
    Fedora Core 2
    python-2.3.3-6
    tk-8.4.5-8
I wrote the following program, in which a worker thread writes to a pipe
which is read by the main thread by a handler that was created by
't.tk.createfilehandler()'.  The program seems to work as expected,
except that the thread usually terminates with an "OSError: Broken pipe"
exception rather than gracefully.

Jeff

#------------------------------------------------------------------------
import sys, Tkinter, threading, os, time

exit_threads = False

reader, writer = os.pipe()
class Worker(threading.Thread):
    def run(self):
        while not exit_threads:
            time.sleep(1)
            os.write(writer, "working\n")
        os.close(writer)

def read(*args):
    data = os.read(reader, 1024)
    tx.insert(Tkinter.END, "%10s: %s" % (time.time(), data))
    tx.see(Tkinter.END)

Worker().start()

t = Tkinter.Tk()
tx = Tkinter.Text(t); tx.pack()
t.tk.createfilehandler(reader, Tkinter.READABLE, read)

try:
    t.mainloop()
finally:
    exit_threads = True
    os.close(reader)
#------------------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050622/c23084e3/attachment.pgp


More information about the Tkinter-discuss mailing list