Anonymous pipes are simple and lightweight pipes, designed to use between the process that creates it and its child processes. Since they are unnamed, the only way to use anonymous pipes is to communicate its handle; there’s no name for the pipe that processes use to obtain access to the pipe. This typically makes anonymous pipes unsuitable for interprocess communication between unrelated processes (for example, between a client and a server process).
Anonymous pipes are simple to create and use. The function
creates an anonymous pipe and returns
two handles: one for reading from the pipe, and one for writing to
the pipe. The
takes the following parameters:
The security attributes for the pipe or
The buffer size or zero for the default.
It then returns a tuple of (
A demonstration of anonymous pipes is quite simple. Let’s create an anonymous pipe (obtaining the two handles), then write some data to the pipe, and read the same data back:
>>> import win32pipe >>> # Create the pipe >>> readHandle, writeHandle = win32pipe.CreatePipe(None, 0) >>> import win32file # This module contains the ReadFile/WriteFile functions. >>> # Write a string to the pipe >>> win32file.WriteFile(writeHandle, "Hi from the pipe") (0, 16) >>> # Now read data from it >>> win32file.ReadFile(readHandle, 16) (0, 'Hi from the pipe') >>>