Blame SOURCES/python-pyudev-0.15-retry-interrupted-calls.patch

199cfe
diff --git a/pyudev/_util.py b/pyudev/_util.py
199cfe
index 266b161..3ce82b2 100644
199cfe
--- a/pyudev/_util.py
199cfe
+++ b/pyudev/_util.py
199cfe
@@ -32,6 +32,7 @@
199cfe
 import os
199cfe
 import sys
199cfe
 import stat
199cfe
+import errno
199cfe
 
199cfe
 
199cfe
 if sys.version_info[0] == 2:
199cfe
@@ -141,3 +142,37 @@ def get_device_type(filename):
199cfe
         return 'block'
199cfe
     else:
199cfe
         raise ValueError('not a device file: {0!r}'.format(filename))
199cfe
+
199cfe
+
199cfe
+def eintr_retry_call(func, *args, **kwargs):
199cfe
+    """
199cfe
+    Handle interruptions to an interruptible system call.
199cfe
+
199cfe
+    Run an interruptible system call in a loop and retry if it raises EINTR.
199cfe
+    The signal calls that may raise EINTR prior to Python 3.5 are listed in
199cfe
+    PEP 0475.  Any calls to these functions must be wrapped in eintr_retry_call
199cfe
+    in order to handle EINTR returns in older versions of Python.
199cfe
+
199cfe
+    This function is safe to use under Python 3.5 and newer since the wrapped
199cfe
+    function will simply return without raising EINTR.
199cfe
+
199cfe
+    This function is based on _eintr_retry_call in python's subprocess.py.
199cfe
+    """
199cfe
+
199cfe
+    # select.error inherits from Exception instead of OSError in Python 2
199cfe
+    import select
199cfe
+
199cfe
+    while True:
199cfe
+        try:
199cfe
+            return func(*args, **kwargs)
199cfe
+        except (OSError, IOError, select.error) as e:
199cfe
+            # If this is not an IOError or OSError, it's the old select.error
199cfe
+            # type, which means that the errno is only accessible via subscript
199cfe
+            if isinstance(e, (OSError, IOError)):
199cfe
+                error_code = e.errno
199cfe
+            else:
199cfe
+                error_code = e.args[0]
199cfe
+
199cfe
+            if error_code == errno.EINTR:
199cfe
+                continue
199cfe
+            raise
199cfe
diff --git a/pyudev/monitor.py b/pyudev/monitor.py
199cfe
index b1eb71c..d87dc2c 100644
199cfe
--- a/pyudev/monitor.py
199cfe
+++ b/pyudev/monitor.py
199cfe
@@ -36,7 +36,7 @@ import select
199cfe
 from threading import Thread
199cfe
 from contextlib import closing
199cfe
 
199cfe
-from pyudev._util import ensure_byte_string, ensure_unicode_string, reraise
199cfe
+from pyudev._util import ensure_byte_string, ensure_unicode_string, reraise, eintr_retry_call
199cfe
 
199cfe
 from pyudev.core import Device
199cfe
 
199cfe
@@ -328,7 +328,7 @@ class Monitor(object):
199cfe
         with closing(select.epoll()) as notifier:
199cfe
             notifier.register(self, select.EPOLLIN)
199cfe
             while True:
199cfe
-                events = notifier.poll()
199cfe
+                events = eintr_retry_call(notifier.poll)
199cfe
                 for event in events:
199cfe
                     yield self.receive_device()
199cfe
 
199cfe
@@ -399,7 +399,7 @@ class MonitorObserver(Thread):
199cfe
             # and on the monitor
199cfe
             notifier.register(self.monitor, select.EPOLLIN)
199cfe
             while True:
199cfe
-                for fd, _ in notifier.poll():
199cfe
+                for fd, _ in eintr_retry_call(notifier.poll):
199cfe
                     if fd == self._stop_event_source:
199cfe
                         # in case of a stop event, close our pipe side, and
199cfe
                         # return from the thread