I am trying to setup two way communication between a daemon and a client using named pipes. The code hangs while trying to open the named pipe used for input Why?
class comm(threading.Thread):
def __init__(self):
self.srvoutf = './tmp/serverout'
self.srvinf = './tmp/serverin'
if os.path.exists(self.srvoutf):
self.pipein = open(self.srvoutf, 'r')
#-----------------------------------------------------Hangs here
else:
os.mkfifo(self.srvoutf)
self.pipein = open(self.srvoutf, 'r')
#-----------------------------------------------------or here
if os.path.exists(self.srvinf):
self.pipeout = os.open(self.srvinf, os.O_WRONLY)
else:
os.mkfifo(self.srvinf)
self.pipeout = os.open(self.srvinf, os.O_WRONLY)
threading.Thread.__init__ ( self )
From the specification for open():
In other words, when you open a named pipe for reading, by default the open will block until the other side of the pipe is opened for writing. To fix this, use
os.open()and passos.O_NONBLOCKon the read side of the named pipe.