Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 709176f

Browse files
committed
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.
1 parent 58bb82e commit 709176f

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

Lib/multiprocessing/connection.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ def arbitrary_address(family):
9494
else:
9595
raise ValueError('unrecognized family')
9696

97+
def _validate_family(family):
98+
'''
99+
Checks if the family is valid for the current environment.
100+
'''
101+
if sys.platform != 'win32' and family == 'AF_PIPE':
102+
raise ValueError('Family %s is not recognized.' % family)
103+
97104

98105
def address_type(address):
99106
'''
@@ -126,6 +133,7 @@ def __init__(self, address=None, family=None, backlog=1, authkey=None):
126133
or default_family
127134
address = address or arbitrary_address(family)
128135

136+
_validate_family(family)
129137
if family == 'AF_PIPE':
130138
self._listener = PipeListener(address, backlog)
131139
else:
@@ -163,6 +171,7 @@ def Client(address, family=None, authkey=None):
163171
Returns a connection to the address of a `Listener`
164172
'''
165173
family = family or address_type(address)
174+
_validate_family(family)
166175
if family == 'AF_PIPE':
167176
c = PipeClient(address)
168177
else:

Lib/test/test_multiprocessing.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2319,8 +2319,20 @@ def test_flushing(self):
23192319
flike.flush()
23202320
assert sio.getvalue() == 'foo'
23212321

2322+
2323+
#
2324+
# Issue 14151: Test invalid family on invalid environment
2325+
#
2326+
2327+
class TestInvalidFamily(unittest.TestCase):
2328+
2329+
@unittest.skipIf(WIN32, "skipped on Windows")
2330+
def test_invalid_family(self):
2331+
with self.assertRaises(ValueError):
2332+
multiprocessing.connection.Listener(r'\\.\test')
2333+
23222334
testcases_other = [OtherTest, TestInvalidHandle, TestInitializers,
2323-
TestStdinBadfiledescriptor]
2335+
TestStdinBadfiledescriptor, TestInvalidFamily]
23242336

23252337
#
23262338
#

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ Core and Builtins
3434
Library
3535
-------
3636

37+
- Issue #14151: Raise a ValueError, not a NameError, when trying to create
38+
a multiprocessing Client or Listener with an AF_PIPE type address under
39+
non-Windows platforms. Patch by Popa Claudiu.
40+
3741
- Issue #13872: socket.detach() now marks the socket closed (as mirrored
3842
in the socket repr()). Patch by Matt Joiner.
3943

0 commit comments

Comments
 (0)