Am Donnerstag, 23. Januar 2014 18:16:05 UTC+1 schrieb Guido van Rossum:

I would have preferred a solution without multiple inheritance but in 
> this case it seems pretty benign, since SubprocessProtocol is just an 
> interface class, while StreamReaderProtocol is an implementation 
> class. A way to avoid the multiple inheritance would be to instantiate 
> a StreamReaderProtocol instance as a member of your SubprocessProtocol 
> subclass constructor.
>
yeah, that’ll work. i’m still confused about that whole factory and 
protocol business :)

the only change to my previous solution would then be:

class StdOutReaderProtocol(SubprocessProtocol):
    def __init__(self, reader, loop=None):
        self.reader_prot = StreamReaderProtocol(reader, loop=loop)
    def pipe_data_received(self, fd, data):
        if fd == 1:
            self.reader_prot.data_received(data)
        else:
            print('stderr from subprocess:', data.decode(), file=sys.stderr, 
end='')

Reply via email to