summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2013-01-08 19:11:29 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2013-01-08 19:02:19 +0000
commitaeb304e756815ebea83701db7b5666ba955be326 (patch)
treec3233f4d6b9648d6a786f41fe80e81f49b7c7d1f
parenta0cd61c13a2e934dc36565e2b9a6c7b08d1279c9 (diff)
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>
-rw-r--r--alot/db/manager.py17
1 files changed, 16 insertions, 1 deletions
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()