summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/gui/widgets/pager.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/ranger/gui/widgets/pager.py b/ranger/gui/widgets/pager.py
index bf7ca5f4..42adf1e9 100644
--- a/ranger/gui/widgets/pager.py
+++ b/ranger/gui/widgets/pager.py
@@ -6,6 +6,7 @@
 from __future__ import (absolute_import, division, print_function)
 
 import curses
+import logging
 
 from ranger.gui import ansi
 from ranger.ext.direction import Direction
@@ -13,9 +14,11 @@ from ranger.ext.img_display import ImgDisplayUnsupportedException
 
 from . import Widget
 
-# TODO: Scrolling in embedded pager
+
+LOG = logging.getLogger(__name__)
 
 
+# TODO: Scrolling in embedded pager
 class Pager(Widget):  # pylint: disable=too-many-instance-attributes
     source = None
     source_is_stream = False
@@ -37,6 +40,14 @@ class Pager(Widget):  # pylint: disable=too-many-instance-attributes
         self.image = None
         self.image_drawn = False
 
+    def _close_source(self):
+        if self.source and self.source_is_stream:
+            try:
+                self.source.close()
+            except OSError as ex:
+                LOG.error('Unable to close pager source')
+                LOG.exception(ex)
+
     def open(self):
         self.scroll_begin = 0
         self.markup = None
@@ -54,8 +65,7 @@ class Pager(Widget):  # pylint: disable=too-many-instance-attributes
         if self.image:
             self.need_clear_image = True
             self.clear_image()
-        if self.source and self.source_is_stream:
-            self.source.close()
+        self._close_source()
 
     def destroy(self):
         self.clear_image(force=True)
@@ -159,9 +169,7 @@ class Pager(Widget):  # pylint: disable=too-many-instance-attributes
         if self.image:
             self.need_clear_image = True
         self.image = image
-
-        if self.source and self.source_is_stream:
-            self.source.close()
+        self._close_source()
         self.source = None
         self.source_is_stream = False
 
@@ -169,9 +177,7 @@ class Pager(Widget):  # pylint: disable=too-many-instance-attributes
         if self.image:
             self.image = None
             self.need_clear_image = True
-
-        if self.source and self.source_is_stream:
-            self.source.close()
+        self._close_source()
 
         self.max_width = 0
         if isinstance(source, str):