QPID-4147: made selector handle interrupt based on patch from siddesh
diff --git a/qpid/selector.py b/qpid/selector.py
index ca5946c..ff94091 100644
--- a/qpid/selector.py
+++ b/qpid/selector.py
@@ -16,7 +16,7 @@
# specific language governing permissions and limitations
# under the License.
#
-import atexit, time
+import atexit, time, errno
from compat import select, set, selectable_waiter
from threading import Thread, Lock
@@ -111,12 +111,24 @@
else:
wakeup = min(wakeup, t)
- if wakeup is None:
- timeout = None
- else:
- timeout = max(0, wakeup - time.time())
+ rd = []
+ wr = []
+ ex = []
- rd, wr, ex = select(self.reading, self.writing, (), timeout)
+ while True:
+ try:
+ if wakeup is None:
+ timeout = None
+ else:
+ timeout = max(0, wakeup - time.time())
+ rd, wr, ex = select(self.reading, self.writing, (), timeout)
+ break
+ except Exception, (err, strerror):
+ # Repeat the select call if we were interrupted.
+ if err == errno.EINTR:
+ continue
+ else:
+ raise
for sel in wr:
if sel.writing():
diff --git a/qpid/tests/messaging/endpoints.py b/qpid/tests/messaging/endpoints.py
index 62deacd..a82a9e9 100644
--- a/qpid/tests/messaging/endpoints.py
+++ b/qpid/tests/messaging/endpoints.py
@@ -1333,3 +1333,15 @@
self.drain(self.rcv, expected=msgs)
self.ssn.acknowledge()
assert caught, "did not exceed capacity"
+
+ def testEINTR(self):
+ m1 = self.content("testEINTR", 0)
+ m2 = self.content("testEINTR", 1)
+
+ self.snd.send(m1, timeout=self.timeout())
+ try:
+ os.setuid(500)
+ assert False, "setuid should fail"
+ except:
+ pass
+ self.snd.send(m2, timeout=self.timeout())