diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2011-11-10 09:39:31 +0000 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2011-11-10 09:39:31 +0000 |
commit | 836bb9a6b87062bcdaa0833f53d40ecdf9c18fbf (patch) | |
tree | 14537ee60d2ad3ad5d597428c5ce16231e84dcfa /alot | |
parent | 317797552f9fee1ef47c8c6cdb649aa6e323323c (diff) |
correctly close pipes
Diffstat (limited to 'alot')
-rw-r--r-- | alot/db.py | 15 | ||||
-rw-r--r-- | alot/walker.py | 8 |
2 files changed, 15 insertions, 8 deletions
@@ -42,17 +42,20 @@ class DatabaseLockedError(DatabaseError): class FillPipeProcess(multiprocessing.Process): - def __init__(self, it, pipe, fun=(lambda x: x)): + def __init__(self, it, pipe_i, pipe_o, fun=(lambda x: x)): multiprocessing.Process.__init__(self) self.it = it - self.pipe = pipe + self.i = pipe_i + self.o = pipe_o self.fun = fun def run(self): try: for a in self.it: - self.pipe.send(self.fun(a)) - self.pipe.send(None) + self.i.send(self.fun(a)) + self.o.close() + self.i.close() + #self.terminate() except IOError: # looks like the main process exited, so we stop pass @@ -194,8 +197,10 @@ class DBManager(object): """return a `Pipe` object to which `fun(a)` is written for each a in cbl""" (i, o) = multiprocessing.Pipe(False) - t = FillPipeProcess(cbl(), o, fun) + t = FillPipeProcess(cbl(), o, i, fun) t.start() + o.close() # guarantees that both ends are closed and i.close in child + # raises EOFError in parent return (i, t) def get_threads(self, querystring): diff --git a/alot/walker.py b/alot/walker.py index b768963d..768485fe 100644 --- a/alot/walker.py +++ b/alot/walker.py @@ -68,11 +68,13 @@ class PipeWalker(urwid.ListWalker): return (None, None) def _get_next_item(self): - next_obj = self.pipe.recv() - if next_obj: + if self.empty: + return None + try: + next_obj = self.pipe.recv() next_widget = self.containerclass(next_obj, **self.kwargs) self.lines.append(next_widget) - else: + except EOFError: next_widget = None self.empty = True return next_widget |