@@ -0,0 +1,877 @@
+%22%22%22%0AProcess 20 lines of output at a time.%0A%0AExample runs:%0Apython buffer_results.py%0A%22%22%22%0Aimport sys%0Aimport time%0Aimport drainers%0A%0A# fake this%0Adef setup_cruncher():%0A    time.sleep(1)%0A%0Adef do_something_expensive(file):%0A    time.sleep(0.005)%0A%0Adef destroy_cruncher():%0A    time.sleep(0.8)%0A%0Afiles = %5B%5D%0A%0Adef crunch(files):%0A    print 'Setting up cruncher...'%0A    setup_cruncher()%0A    while len(files) %3E 0:%0A        f = files.pop(0)%0A        print '- Crunching file %25s...' %25 f.strip()%0A        do_something_expensive(f)%0A    print 'Releasing cruncher...'%0A    destroy_cruncher()%0A%0Adef add_to_buffer(line, is_err):%0A    if is_err:%0A        # ignore all errors%0A        return%0A    files.append(line)%0A%0A    # start crunch synchronously after 20 items have been read%0A    if len(files) %3E= 20:%0A        crunch(files)%0A%0Ad = drainers.Drainer(%5B'find', '.', '-type', 'f'%5D, read_event_cb=add_to_buffer)%0Ad.start()%0A

Add result buffering/batch processing example.