diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2018-07-31 09:08:48 -0700 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2019-08-15 20:44:32 +0100 |
commit | e7e0c52db9093a9ecd9dcaa0766e66515a546a75 (patch) | |
tree | d669b366f43cc3cdbc7c57020deb8230ac69158a /alot/walker.py | |
parent | cd44abdc4df887e1e9ed70e510560fc26e62f97e (diff) |
db/manager: Drop async method
As far as I can tell using a separate process doesn't actually improve
performance, it makes it worse. The work that we're passing off to the
separate function isn't necessarily work that's well suited to being
handed off, there isn't a lot of computation and the objects that need
to be passed across the pipe are fairly large (at least when considering
a pipe). Converting the function to a generator gives better performance
and simplifies the implementation.
Diffstat (limited to 'alot/walker.py')
-rw-r--r-- | alot/walker.py | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/alot/walker.py b/alot/walker.py index e4264103..cfefc9e6 100644 --- a/alot/walker.py +++ b/alot/walker.py @@ -1,20 +1,30 @@ # Copyright (C) 2011-2012 Patrick Totzke <patricktotzke@gmail.com> +# Copyright © 2018 Dylan Baker # This file is released under the GNU GPL, version 3 or a later revision. # For further details see the COPYING file import logging import urwid -class PipeWalker(urwid.ListWalker): - """urwid.ListWalker that reads next items from a pipe and wraps them in - `containerclass` widgets for displaying +class IterableWalker(urwid.ListWalker): - Attributes that should be considered publicly readable: - :attr lines: the lines obtained from the pipe - :type lines: list(`containerclass`) + """An urwid walker for iterables. + + Works like ListWalker, except it takes an iterable object instead of a + concrete type. This allows for lazy operations of very large sequences of + data, such as a sequences of threads with certain notmuch tags. + + :param iterable: An iterator of objects to walk over + :type iterable: Iterable[T] + :param containerclass: An urwid widget to wrap each object in + :type containerclass: urwid.Widget + :param reverse: Reverse the order of the iterable + :type reverse: bool + :param **kwargs: Forwarded to container class. """ - def __init__(self, pipe, containerclass, reverse=False, **kwargs): - self.pipe = pipe + + def __init__(self, iterable, containerclass, reverse=False, **kwargs): + self.iterable = iterable self.kwargs = kwargs self.containerclass = containerclass self.lines = [] @@ -71,10 +81,10 @@ class PipeWalker(urwid.ListWalker): try: # the next line blocks until it can read from the pipe or # EOFError is raised. No races here. - next_obj = self.pipe.recv() + next_obj = next(self.iterable) next_widget = self.containerclass(next_obj, **self.kwargs) self.lines.append(next_widget) - except EOFError: + except StopIteration: logging.debug('EMPTY PIPE') next_widget = None self.empty = True |