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

Skip to content

Commit 93bba8f

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.
2 parents 0261d75 + 709176f commit 93bba8f

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
@@ -104,6 +104,13 @@ def arbitrary_address(family):
104104
else:
105105
raise ValueError('unrecognized family')
106106

107+
def _validate_family(family):
108+
'''
109+
Checks if the family is valid for the current environment.
110+
'''
111+
if sys.platform != 'win32' and family == 'AF_PIPE':
112+
raise ValueError('Family %s is not recognized.' % family)
113+
107114

108115
def address_type(address):
109116
'''
@@ -436,6 +443,7 @@ def __init__(self, address=None, family=None, backlog=1, authkey=None):
436443
or default_family
437444
address = address or arbitrary_address(family)
438445

446+
_validate_family(family)
439447
if family == 'AF_PIPE':
440448
self._listener = PipeListener(address, backlog)
441449
else:
@@ -473,6 +481,7 @@ def Client(address, family=None, authkey=None):
473481
Returns a connection to the address of a `Listener`
474482
'''
475483
family = family or address_type(address)
484+
_validate_family(family)
476485
if family == 'AF_PIPE':
477486
c = PipeClient(address)
478487
else:

Lib/test/test_multiprocessing.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2638,8 +2638,20 @@ def test_wait_integer(self):
26382638
p.join()
26392639

26402640

2641+
#
2642+
# Issue 14151: Test invalid family on invalid environment
2643+
#
2644+
2645+
class TestInvalidFamily(unittest.TestCase):
2646+
2647+
@unittest.skipIf(WIN32, "skipped on Windows")
2648+
def test_invalid_family(self):
2649+
with self.assertRaises(ValueError):
2650+
multiprocessing.connection.Listener(r'\\.\test')
2651+
2652+
26412653
testcases_other = [OtherTest, TestInvalidHandle, TestInitializers,
2642-
TestStdinBadfiledescriptor, TestWait]
2654+
TestStdinBadfiledescriptor, TestWait, TestInvalidFamily]
26432655

26442656
#
26452657
#

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ Core and Builtins
4040
Library
4141
-------
4242

43+
- Issue #14151: Raise a ValueError, not a NameError, when trying to create
44+
a multiprocessing Client or Listener with an AF_PIPE type address under
45+
non-Windows platforms. Patch by Popa Claudiu.
46+
4347
- Issue #14300: Under Windows, sockets created using socket.dup() now allow
4448
overlapped I/O. Patch by sbt.
4549

0 commit comments

Comments
 (0)