I’ve been working a bit with pipes in Python, using the
subprocess
module to
kick off a couple of processes, a client and a server, and using pipes to
redirect their input and output in such a way as to test them. I thought it
might be an idea to write about using pipes primarily from a Python viewpoint,
with a view especially to clarifying things like blocking and buffering.
In the course of this tutorial we will develop a testing tool for a pair of
programs. This tool will be able to start both programs, issue some commands to
both of them and then source its input from named pipes, allowing the user to
enter their own commands as and when they see fit. The output will be provided
via stdout
and will be the multiplexed output of both prgrams, prefixed with
an appropriate identifying prefix. A typical use case of this testing tool (and
what I am using it for) is testing a client and server, by which I need to fire
up both client and server, automate the entry of some configuration commands
and then have manual control to enter more commands to both client and server.
The tutorial is broken into the following pieces: