def cooperative_read(fd):
 def readfn(*args):
  result = fd.read(*args)
  sleep(0)
  return result
 return readfn

def cooperative_read ( fd ) : def readfn ( * args ) : result = fd . read ( * args ) sleep ( 0 ) return result return readfn
wrap a file descriptors read with a partial function which schedules after each read .