I am communicating between two python scripts via pipes (Python 3.6.0 on osx). In the ideal case where the message is sent and waiting in the pipe, reading it isn't a problem. However when the pipe is empty it hangs while trying to read it.
Here is the script that writes to the pipe:
import pipes
pipe_path = "/tmp/mypipe"
t = pipes.Template()
t.append('tr a-z A-Z', '--')
f = t.open(pipe_path, 'w')
f.write('ping')
Here is the script that that reads it:
import pipes
pipe_path = "/tmp/mypipe"
t = pipes.Template()
t.append('tr a-z A-Z', '--')
f = t.open(pipe_path, 'r')
txt = f.read()
print(txt)
So if I run the second script without running the first one it hangs. How can I detect if the pipe is empty and avoid it hanging on f.read()
?