[pygtk] Asynchronously Opening and Reading Large Files

Mystilleef mystilleef at gmail.com
Tue Jul 26 01:14:19 WST 2005


On 7/25/05, Gustavo J. A. M. Carneiro <gjc at inescporto.pt> wrote:
>   In open_cb, schedule a _single_ read of block size; In read_cb, read
> what there is to read, then schedule another read using the same
> callback, until you've read the entire file.

Awesome! That worked.

------------------------------------------------------------

# Insert Text into a GTK Buffer
	
def read_cb(handle, buffer, exc_type, bytes_requested):
	
	if buffer != "":
	
		txt_buffer.insert_at_cursor(buffer)
		handle.read(opt_size, read_cb)
		
	else:
		
		handle.close(close_cb)
	
# Try to read files 4096 bytes at a time 	
	
def open_cb(handle, exec_type):
	
	handle.read(opt_size, read_cb)
	
# Open a file asynchronously
	
gnomevfs.async.open(filename, open_cb)

------------------------------------------------------------

Thanks a lot folks. 

Thanks

> 
>   PS: the classes VFSAsyncBaseGUI, VFSAsyncLoaderGUI, and
> VFSAsyncSaverGUI in [1] may be useful to you.
> 
> 
> [1] >http://cvs.sourceforge.net/viewcvs.py/numexp/gnumexp/src/xygraph/Numexp_XYGraph/persist.py?view=auto


More information about the pygtk mailing list