Reputation: 1811
I have two scripts:
The first one ('Reader') is reading data from named pipe and the second ('Writer') is writing data to named pipe. I am run 'Writer' from daemon (daemon was created with double fork mechanism). If 'Writer' crash I want to print a message about it in 'Reader'. Please see following Python code('Reader'):
pipe = open(pipe_path, 'r')
while True:
data = pipe.readline()
if not data:
print('Alarm')
break
But when 'Writer' is crashing then 'Reader' is stuck on following line:
data = pipe.readline()
But if I run 'Writer' from terminal everything works fine (Alarm message is printing when not data in pipe). And everything works fine if I open pipe with:
os.open(pipe_path, os.O_RDONLY | os.O_NONBLOCK)
But this method not suitable for me because I need to wait a time on start when 'Writer' start write data into pipe
In order not to create a zombie I do next in daemon:
def childHandler(signum, frame):
os.wait3(os.WNOHANG)
signal.signal(signal.SIGCHLD, zombieKiller)
How to prevent the 'Reader' stuck and correctly handle the signal from the child process ?
Upvotes: 1
Views: 399
Reputation:
Try to use this in the daemon:
fdPipe = os.open(pipe_path, os.O_WRONLY | os.O_NONBLOCK)
Upvotes: 1