What is the process to run sub-process with pipes that connect both input and output?
Answer Posted / chaitanya
The popen2() module is used to run the sub-process but due to some difficulty in processing like creation of deadlock that keep a process blocked that wait for the output from the child and child is waiting for the input. The dead lock occurs due to the fact that parent and child doesn’t have the synchronization and both are waiting to get the processor to provide the resources to one another. Use of popen3() method allow the reading of stdout and stderr to take place where the internal buffer increases and there is no read() takes place to share the resources. popen2() take care of the deadlock by providing the methods like wait() and waitpid() that finishes a process first and when a request comes it hands over the responsibility to the process that is waiting for the resources. The program is used to show the process and run it.
import popen2
fromchild, tochild = popen2.popen2("command")
tochild.write("input
")
tochild.flush()
output = fromchild.readline()
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
How many hours should a person sleep?
Do you need python to run a python program?
Is nan a float python?
How do I install pip?
Explain me inheritance in python with an example?
Is python list an array?
Is python an oop?
Explain join() and split() in python.
What is the keyword to import a module in python?
What packages in the standard library, useful for data science work, do you know?
How do I emulate os.kill() in windows?
Does range start at 0 python?
What is the purpose of __ init __?
Explain python’s pass by references vs pass by value.
What is pass in Python?