etc ctrl- to exit notice how the parent received bytes string through the pipe raw pipes normally deal in binary byte strings when their descriptors are used directly this way with the descriptor-based file tools we met in (as we saw theredescriptor read and write tools in os always return and expect byte stringsthat' why we also have to manually encode to bytes when writing in the child--the string formatting operation is not available on bytes as the next section showsit' also possible to wrap pipe descriptor in text-mode file objectmuch as we did in the file examples in but that object simply performs encoding and decoding automatically on transfersit' still bytes in the pipe wrapping pipe descriptors in file objects if you look closely at the preceding outputyou'll see that when the child' delay counter hits the parent ends up reading two messages from the pipe at the same timethe child wrote two distinct messagesbut on some platforms or configurations (other than that used herethey might be interleaved or processed close enough in time to be fetched as single unit by the parent reallythe parent blindly asks to readat most bytes each timebut it gets back whatever text is available in the pipewhen it becomes available to distinguish messages betterwe can mandate separator character in the pipe an end-of-line makes this easybecause we can wrap the pipe descriptor in file object with os fdopen and rely on the file object' readline method to scan up through the next \ separator in the pipe this also lets us leverage the more powerful tools of the text-mode file object we met in example - implements this scheme for the parent' end of the pipe example - pp \system\processes\pipe py same as pipe pybut wrap pipe input in stdio file object to read by lineand close unused pipe fds in both processes import ostime def child(pipeout)zzz while truetime sleep(zzzmsg ('spam % \nzzzencode(os write(pipeoutmsgzzz (zzz+ def parent()pipeinpipeout os pipe(if os fork(= os close(pipeinchild(pipeout parallel system tools make parent wait pipes are binary in send to parent roll to at make -ended pipe in childwrite to pipe close input side here