'input is a pipe and output is file-like. if lock is non-None, then
we assume output isn\'t thread-safe'

@staticmethod
def _fd_drainer(input_pipe, outputs, lock):

    acquire = getattr(lock, 'acquire', bool)
    release = getattr(lock, 'release', bool)
    writable_objs = [obj for obj in outputs if hasattr(obj, 'write')]
    fileno = input_pipe.fileno()
    while True:
        tmp = os.read(fileno, 1024)
        if (tmp == ''):
            break
        acquire()
        try:
            for f in writable_objs:
                f.write(tmp)
        finally:
            release()
