diff options
-rw-r--r-- | ranger/__main__.py | 12 | ||||
-rw-r--r-- | ranger/core/fm.py | 15 | ||||
-rw-r--r-- | ranger/core/loader.py | 23 |
3 files changed, 41 insertions, 9 deletions
diff --git a/ranger/__main__.py b/ranger/__main__.py index 8bb0bfa1..d25065a1 100644 --- a/ranger/__main__.py +++ b/ranger/__main__.py @@ -187,10 +187,10 @@ def main(): else: path = '.' + # Initialize objects + EnvironmentAware._assign(Environment(path)) + fm = FM() try: - # Initialize objects - EnvironmentAware._assign(Environment(path)) - fm = FM() load_settings(fm, ranger.arg.clean) FileManagerAware._assign(fm) fm.ui = UI() @@ -200,11 +200,7 @@ def main(): fm.ui.initialize() fm.loop() finally: - # Finish, clean up - try: - fm.ui.destroy() - except (AttributeError, NameError): - pass + fm.destroy() if __name__ == '__main__': diff --git a/ranger/core/fm.py b/ranger/core/fm.py index 0702e472..7a55afa7 100644 --- a/ranger/core/fm.py +++ b/ranger/core/fm.py @@ -94,6 +94,21 @@ class FM(Actions, SignalDispatcher): self.env.signal_bind('cd', self._update_current_tab) + def destroy(self): + debug = ranger.arg.debug + if self.ui: + try: + self.ui.destroy() + except: + if debug: + raise + if self.loader: + try: + self.loader.destroy() + except: + if debug: + raise + def block_input(self, sec=0): self.input_blocked = sec != 0 self.input_blocked_until = time() + sec diff --git a/ranger/core/loader.py b/ranger/core/loader.py index 24dac464..53d9dc6e 100644 --- a/ranger/core/loader.py +++ b/ranger/core/loader.py @@ -30,14 +30,25 @@ def status_generator(): yield '\\' yield '|' + class LoadableObject(object): def __init__(self, gen, descr): self.load_generator = gen self.description = descr + self.paused = False def get_description(self): return self.description + def pause(self): + self.paused = True + + def unpause(self): + self.paused = False + + def destroy(self): + pass + class CommandLoader(LoadableObject): def __init__(self, args, descr, begin_hook=None, end_hook=None): @@ -47,7 +58,9 @@ class CommandLoader(LoadableObject): self.end_hook = end_hook def generate(self): - process = Popen(self.args, stdout=open(os.devnull, 'w'), stderr=PIPE) + self.process = process = Popen(self.args, + stdout=open(os.devnull, 'w'), + stderr=PIPE) if self.begin_hook: self.begin_hook(process) while process.poll() is None: @@ -60,6 +73,10 @@ class CommandLoader(LoadableObject): if self.end_hook(process): self.end_hook(process) + def destroy(self): + if self.process: + self.process.kill() + class Loader(FileManagerAware): seconds_of_work_time = 0.03 @@ -151,3 +168,7 @@ class Loader(FileManagerAware): def has_work(self): """Is there anything to load?""" return bool(self.queue) + + def destroy(self): + while self.queue: + self.queue.pop().destroy() |