#!/usr/bin/env python
import os,select,time

BUFF_SIZE = 1024
outdata="0123456789abcdef"*1024
indata=""

i,o = os.popen2('python staller.py')
time.sleep(0.1)  # small delay to emphasise problem on fast computers
li,lo = [i],[o]
while li or lo:
    ro,ri,re = select.select(lo,li,[])
    if ri:
        if outdata:
            print "writing %d bytes" % BUFF_SIZE
            i.write(outdata[:BUFF_SIZE])
            print "finished write"
            outdata=outdata[BUFF_SIZE:]
        else:
            i.close()
            li=[]
    if ro:
        print "starting read"
        data = o.read(BUFF_SIZE)
        print "read %d bytes" % len(data)
        if data:
            indata = indata + data
        else:
            o.close()
            lo=[]

