22 Jun 2005 14:54
Re: Help: _tkinter.createfilehandler not supported for threaded Tcl
Jeff Epler <jepler <at> unpythonic.net>
2005-06-22 12:54:08 GMT
2005-06-22 12:54:08 GMT
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)
#------------------------------------------------------------------------
_______________________________________________ Tkinter-discuss mailing list Tkinter-discuss <at> python.org http://mail.python.org/mailman/listinfo/tkinter-discuss
RSS Feed