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
Print contents of a file ensuring proper error handling?
How do you run a python script?
Which is faster python or php?
Tell me how to find bugs or perform static analysis in a python application?
Explain about multi-threading concept in python?
List out the different types of inheritance available in python?
How will you locally save an image using its url address?
How to check whether a module is installed in python?
Write the command to get all keys from the dictionary.
What kinds of patterns could I enforce on the code to make it easier to translate to another programming language?
Explain about python break, continue and pass?
What is setuptools in python?
What is raw input function in python?
Is python an oops?
What is the Java implementation of Python popularly known as?