[Python-checkins] cpython (merge 3.3 -> default): Fix test.support.bind_port() to not cause an error when Python was compiled

gregory.p.smith python-checkins at python.org
Sun Nov 17 23:21:26 CET 2013


http://hg.python.org/cpython/rev/00766fa3366b
changeset:   87225:00766fa3366b
parent:      87223:0fbdff3fde3a
parent:      87224:9791c5d55f52
user:        Gregory P. Smith <greg at krypto.org>
date:        Sun Nov 17 22:21:02 2013 +0000
summary:
  Fix test.support.bind_port() to not cause an error when Python was compiled
on a system with SO_REUSEPORT defined in the headers but run on a system
with an OS kernel that does not support that reasonably new socket option.

files:
  Lib/test/support/__init__.py |  12 +++++++++---
  Misc/NEWS                    |   4 ++++
  2 files changed, 13 insertions(+), 3 deletions(-)


diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -594,9 +594,15 @@
                 raise TestFailed("tests should never set the SO_REUSEADDR "   \
                                  "socket option on TCP/IP sockets!")
         if hasattr(socket, 'SO_REUSEPORT'):
-            if sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT) == 1:
-                raise TestFailed("tests should never set the SO_REUSEPORT "   \
-                                 "socket option on TCP/IP sockets!")
+            try:
+                if sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT) == 1:
+                    raise TestFailed("tests should never set the SO_REUSEPORT "   \
+                                     "socket option on TCP/IP sockets!")
+            except OSError:
+                # Python's socket module was compiled using modern headers
+                # thus defining SO_REUSEPORT but this process is running
+                # under an older kernel that does not support SO_REUSEPORT.
+                pass
         if hasattr(socket, 'SO_EXCLUSIVEADDRUSE'):
             sock.setsockopt(socket.SOL_SOCKET, socket.SO_EXCLUSIVEADDRUSE, 1)
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -50,6 +50,10 @@
 Library
 -------
 
+- Fix test.support.bind_port() to not cause an error when Python was compiled
+  on a system with SO_REUSEPORT defined in the headers but run on a system
+  with an OS kernel that does not support that reasonably new socket option.
+
 - Fix compilation error under gcc of the ctypes module bundled libffi for arm.
 
 - Issue #19448: Add private API to SSL module to lookup ASN.1 objects by OID,

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list