Issue #14151: Raise a ValueError, not a NameError, when trying to create
a multiprocessing Client or Listener with an AF_PIPE type address under
non-Windows platforms. Patch by Popa Claudiu.
diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py
index df00f1d..fa6f7b3 100644
--- a/Lib/multiprocessing/connection.py
+++ b/Lib/multiprocessing/connection.py
@@ -94,6 +94,13 @@
else:
raise ValueError('unrecognized family')
+def _validate_family(family):
+ '''
+ Checks if the family is valid for the current environment.
+ '''
+ if sys.platform != 'win32' and family == 'AF_PIPE':
+ raise ValueError('Family %s is not recognized.' % family)
+
def address_type(address):
'''
@@ -126,6 +133,7 @@
or default_family
address = address or arbitrary_address(family)
+ _validate_family(family)
if family == 'AF_PIPE':
self._listener = PipeListener(address, backlog)
else:
@@ -163,6 +171,7 @@
Returns a connection to the address of a `Listener`
'''
family = family or address_type(address)
+ _validate_family(family)
if family == 'AF_PIPE':
c = PipeClient(address)
else:
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py
index 8edb420..8de7a8d 100644
--- a/Lib/test/test_multiprocessing.py
+++ b/Lib/test/test_multiprocessing.py
@@ -2319,8 +2319,20 @@
flike.flush()
assert sio.getvalue() == 'foo'
+
+#
+# Issue 14151: Test invalid family on invalid environment
+#
+
+class TestInvalidFamily(unittest.TestCase):
+
+ @unittest.skipIf(WIN32, "skipped on Windows")
+ def test_invalid_family(self):
+ with self.assertRaises(ValueError):
+ multiprocessing.connection.Listener(r'\\.\test')
+
testcases_other = [OtherTest, TestInvalidHandle, TestInitializers,
- TestStdinBadfiledescriptor]
+ TestStdinBadfiledescriptor, TestInvalidFamily]
#
#
diff --git a/Misc/NEWS b/Misc/NEWS
index 4bf3a91..2fa911e 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -34,6 +34,10 @@
Library
-------
+- Issue #14151: Raise a ValueError, not a NameError, when trying to create
+ a multiprocessing Client or Listener with an AF_PIPE type address under
+ non-Windows platforms. Patch by Popa Claudiu.
+
- Issue #13872: socket.detach() now marks the socket closed (as mirrored
in the socket repr()). Patch by Matt Joiner.