From d599ab1580d307e4a83f6a55eb4cba70a63e1a2f Mon Sep 17 00:00:00 2001 From: nfnty Date: Mon, 29 Feb 2016 13:39:35 +0100 Subject: VCS: pause thread during ui.suspend() --- ranger/config/commands.py | 4 ++-- ranger/container/directory.py | 2 +- ranger/ext/vcs/vcs.py | 20 ++++++++++++++++++-- ranger/gui/ui.py | 7 +++++++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/ranger/config/commands.py b/ranger/config/commands.py index 04b71f8a..842d4f4e 100755 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -1364,7 +1364,7 @@ class stage(Command): self.fm.thisdir.vcs.action_add(filelist) except VcsError as error: self.fm.notify('Unable to stage files: {0:s}'.format(str(error))) - self.fm.ui.vcsthread.wakeup(self.fm.thisdir) + self.fm.ui.vcsthread.process(self.fm.thisdir) else: self.fm.notify('Unable to stage files: Not in repository') @@ -1383,7 +1383,7 @@ class unstage(Command): self.fm.thisdir.vcs.action_reset(filelist) except VcsError as error: self.fm.notify('Unable to unstage files: {0:s}'.format(str(error))) - self.fm.ui.vcsthread.wakeup(self.fm.thisdir) + self.fm.ui.vcsthread.process(self.fm.thisdir) else: self.fm.notify('Unable to unstage files: Not in repository') diff --git a/ranger/container/directory.py b/ranger/container/directory.py index 8ace0d85..e7c2b4b6 100644 --- a/ranger/container/directory.py +++ b/ranger/container/directory.py @@ -386,7 +386,7 @@ class Directory(FileSystemObject, Accumulator, Loadable): self.loading = False self.fm.signal_emit("finished_loading_dir", directory=self) if self.vcs: - self.fm.ui.vcsthread.wakeup(self) + self.fm.ui.vcsthread.process(self) def unload(self): self.loading = False diff --git a/ranger/ext/vcs/vcs.py b/ranger/ext/vcs/vcs.py index fd34c3fe..487c9405 100644 --- a/ranger/ext/vcs/vcs.py +++ b/ranger/ext/vcs/vcs.py @@ -370,6 +370,9 @@ class VcsThread(threading.Thread): # pylint: disable=too-many-instance-attribut self.daemon = True self.ui = ui # pylint: disable=invalid-name self.queue = queue.Queue() + self.advance = threading.Event() + self.advance.set() + self.paused = threading.Event() self.awoken = threading.Event() self.timestamp = time.time() self.redraw = False @@ -442,7 +445,12 @@ class VcsThread(threading.Thread): # pylint: disable=too-many-instance-attribut def run(self): while True: + self.paused.set() + self.advance.wait() self.awoken.wait() + if not self.advance.isSet(): + continue + self.paused.clear() self.awoken.clear() self._queue_process() @@ -455,8 +463,16 @@ class VcsThread(threading.Thread): # pylint: disable=too-many-instance-attribut self.ui.status.need_redraw = True self.ui.redraw() - def wakeup(self, dirobj): - """Wakeup thread""" + def pause(self): + """Pause thread""" + self.advance.clear() + + def unpause(self): + """Unpause thread""" + self.advance.set() + + def process(self, dirobj): + """Process dirobj""" self.queue.put(dirobj) self.awoken.set() diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py index 41b57c2c..ad95d754 100644 --- a/ranger/gui/ui.py +++ b/ranger/gui/ui.py @@ -94,8 +94,15 @@ class UI(DisplayableContainer): sys.stdout.write("\033kranger\033\\") sys.stdout.flush() + if 'vcsthread' in self.__dict__: + self.vcsthread.unpause() + def suspend(self): """Turn off curses""" + if 'vcsthread' in self.__dict__: + self.vcsthread.pause() + self.vcsthread.paused.wait() + self.win.keypad(0) curses.nocbreak() curses.echo() -- cgit 1.4.1-2-gfad0