Reputation: 3789
I am facing a problem where I want to take input from the terminal but am not able to get. The reason I can think of is because there has been a socket opened in this end.I have explained the overview of the structure as follows:
I have a program which opens a socket. Then I open another process and in that process I have the input
statement from which I want to take the input, but it doesn't work. print
statement is working fine everywhere except after the input statement.
mainFile.py:
if __name__ == "__main__":
pose_face = face.Pose_Face()
async_lesson = Process(target=lesson.start_lesson, args=(lesson_args,return_dict))
face.py:
class Pose_Face:
def __init__(self):
context = zmq.Context()
print("Connecting openface server..")
self.socket = context.socket(zmq.REQ)
self.socket.connect("tcp://127.0.0.1:5562")
lesson.py:
class lesson:
def start_lesson(d,return_dict):
txt_resp = input("Enter Text ") //TAKING INPUT
print("text input : " + txt_resp) //THIS IS NOT GETTING PRINTED
I have just given a short version of the code as this problem I guess is not code dependent but mostly concept dependent. I tried searching for ways to do this but am not able to. In the terminal the statement Enter Text
comes and when I enter the text and press Enter
nothing happens and even the next print line is not printed.
Edit : Using Ubuntu terminal, if this information helps in any way. Also, after executing these two statements in my mainFile.py I am also drawing a matplot graph which stays there all the time(needed).
Upvotes: 0
Views: 231
Reputation: 148975
Socket is not the problem here. But reading from the terminal in multi-processing is hazardous if you do not setup some synchronization. When multiple threads or processes write on the same stream, the worse possible behaviour is a strange mix of all the outputs. But when multiple threads of processes compete for reading on same input stream one (at random) will get some input and others will not even see it.
The rule is one single reader per input stream.
Upvotes: 1