From aeb304e756815ebea83701db7b5666ba955be326 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Tue, 8 Jan 2013 19:11:29 +0100 Subject: Ignore EINTR in workers when terminating due to SIGTERM If the child process is killed using SIGTERM by the parent, send(2) can fail with EINTR. Install a signal handler for SIGTERM and ignore EINTR in this particular case. Fixes #325. Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de> --- alot/db/manager.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'alot/db') diff --git a/alot/db/manager.py b/alot/db/manager.py index 3c938f9b..535186b5 100644 --- a/alot/db/manager.py +++ b/alot/db/manager.py @@ -5,6 +5,9 @@ from notmuch import Database, NotmuchError, XapianError import notmuch import multiprocessing import logging +import sys +import errno +import signal from collections import deque @@ -24,10 +27,22 @@ class FillPipeProcess(multiprocessing.Process): self.it = it self.pipe = pipe[1] self.fun = fun + self.keep_going = True + + def handle_sigterm(self, signo, frame): + self.keep_going = False + sys.exit() def run(self): + signal.signal(signal.SIGTERM, self.handle_sigterm) + for a in self.it: - self.pipe.send(self.fun(a)) + try: + self.pipe.send(self.fun(a)) + except IOError as e: + if e.errno != errno.EINTR or self.keep_going: + raise + self.pipe.close() -- cgit v1.2.3