From bfc8a0ece32c8e52288563c0c6e3a01be81cb60f Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Mon, 30 Jul 2012 23:03:46 +0000 Subject: QPID-4147: made selector handle interrupt based on patch from siddesh git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1367354 13f79535-47bb-0310-9956-ffa450edef68 --- python/qpid/selector.py | 24 ++++++++++++++++++------ python/qpid/tests/messaging/endpoints.py | 12 ++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) (limited to 'python') diff --git a/python/qpid/selector.py b/python/qpid/selector.py index ca5946c3f9..ff94091da0 100644 --- a/python/qpid/selector.py +++ b/python/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 @@ class Selector: 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/python/qpid/tests/messaging/endpoints.py b/python/qpid/tests/messaging/endpoints.py index 62deacd0bd..a82a9e95ed 100644 --- a/python/qpid/tests/messaging/endpoints.py +++ b/python/qpid/tests/messaging/endpoints.py @@ -1333,3 +1333,15 @@ class SenderTests(Base): 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()) -- cgit v1.2.1