@tasklet.task def transfer_file(filein, fileout): fin = open(filein, "r") fout = open(fileout, "w") read_chan = gobject.IOChannel(fin) read_chan.set_flags(gobject.IO_FLAG_NONBLOCK) write_chan = gobject.IOChannel(fout) write_chan.set_flags(gobject.IO_FLAG_NONBLOCK) while True: assert read_chan.get_flags() & gobject.IO_FLAG_IS_READABLE yield tasklet.WaitForIO(read_chan, gobject.IO_IN) tasklet.get_event() c = chan.read(BUFFER_SIZE) raise StopIteration(c) assert write_chan.get_flags() & gobject.IO_FLAG_IS_WRITEABLE yield tasklet.WaitForIO(write_chan, gobject.IO_OUT) tasklet.get_event() chan.write(c) fin.close() fout.close()