in parentlisten to pipe os close(pipeoutclose output side here pipein os fdopen(pipeinmake text mode input file object while trueline pipein readline()[:- blocks until data sent print('parent % got [%sat % (os getpid()linetime time())parent(this version has also been augmented to close the unused end of the pipe in each process ( after the forkthe parent process closes its copy of the output side of the pipe written by the child)programs should close unused pipe ends in general running with this new version reliably returns single child message to the parent each time it reads from the pipebecause they are separated with markers when written[ :\pp \system\processes]python pipe py parent got [spam at parent got [spam at parent got [spam at parent got [spam at parent got [spam at parent got [spam at parent got [spam at parent got [spam at parent got [spam at parent got [spam at parent got [spam at parent got [spam at etc ctrl- to exit notice that this version' reads also return text data str object nowper the default text mode for os fdopen as mentionedpipes normally deal in binary byte strings when their descriptors are used directly with os file toolsbut wrapping in text-mode files allows us to use str strings to represent text data instead of bytes in this examplebytes are decoded to str when read by the parentusing os fdopen and text mode in the child would allow us to avoid its manual encoding callbut the file object would encode the str data anyhow (though the encoding is trivial for ascii bytes like those used hereas for simple filesthe best mode for processing pipe data in is determined by its nature anonymous pipes and threads although the os fork call required by the prior section' examples isn' available on standard windows pythonos pipe is because threads all run in the same process and share file descriptors (and global memory in general)this makes anonymous pipes usable as communication and synchronization device for threadstoo this is an arguably lower-level mechanism than queues or shared names and objectsbut it provides an additional ipc option for threads example - for instancedemonstrates the same type of pipe-based communication occurring between threads instead of processes interprocess communication