Async File I/O

Randall Hopper aa8vb at -nojunk-ipass.net
Fri Feb 18 19:22:10 EST 2000


Randall Hopper <aa8vb at -nojunk-ipass.net> wrote:
 |Is there a way to perform asynchronous file I/O in Python which is
 |compatible with Tkinter?
 |
 |I believe Tk's fileevent might be it, but I don't see any wrapper in 
 |the Tkinter module.  Anyone have a code snippet they could share?

Never mind.  I found the code bite I needed buried in Dejanews.  The answer
for Tkinter (on UNIX) is "createfilehandler".

UNIX is sufficient for my needs.  But what do Tkinter folks do with this
situation on MSWindows?  Sleep and poll?  Or is there another API that's
used?

-- 
Randall Hopper
aa8vb at -nojunk-ipass.net


===============================================================================
#!/usr/bin/env python
#  From: Olaf Delgado <delgado at Mathematik.Uni-Bielefeld.DE>
#  Date: 03 May 1999 00:00:00 GMT
#  Subject: Re: Tkinter and fileevent

import sys
import Tkinter
import tkMessageBox

root = Tkinter.Tk()

def stdin_handler(file, mask):
    root.tk.deletefilehandler(file)
    if not tkMessageBox.askokcancel("Go on?", file.readline()):
        root.destroy()
    root.tk.createfilehandler(file, mask, stdin_handler)

root.tk.createfilehandler(sys.stdin, Tkinter.READABLE, stdin_handler)

root.mainloop()
===============================================================================



More information about the Python-list mailing list