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

Skip to content

Commit e51c8da

Browse files
author
Charles-François Natali
committed
Issue #12981: test_multiprocessing: catch ImportError when importing
multiprocessing.reduction, which may not be available (e.g. if the OS doesn't support FD passing over Unix domain sockets).
1 parent 4507e64 commit e51c8da

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

Lib/test/test_multiprocessing.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@
3535
import multiprocessing.heap
3636
import multiprocessing.pool
3737

38-
from multiprocessing import util, reduction
38+
from multiprocessing import util
39+
40+
try:
41+
from multiprocessing import reduction
42+
HAS_REDUCTION = True
43+
except ImportError:
44+
HAS_REDUCTION = False
3945

4046
try:
4147
from multiprocessing.sharedctypes import Value, copy
@@ -1582,6 +1588,7 @@ def _writefd(cls, conn, data, create_dummy_fds=False):
15821588
os.write(fd, data)
15831589
os.close(fd)
15841590

1591+
@unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction")
15851592
def test_fd_transfer(self):
15861593
if self.TYPE != 'processes':
15871594
self.skipTest("only makes sense with processes")
@@ -1600,6 +1607,7 @@ def test_fd_transfer(self):
16001607
with open(test.support.TESTFN, "rb") as f:
16011608
self.assertEqual(f.read(), b"foo")
16021609

1610+
@unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction")
16031611
@unittest.skipIf(sys.platform == "win32",
16041612
"test semantics don't make sense on Windows")
16051613
@unittest.skipIf(MAXFD <= 256,
@@ -1636,6 +1644,7 @@ def test_large_fd_transfer(self):
16361644
def _send_data_without_fd(self, conn):
16371645
os.write(conn.fileno(), b"\0")
16381646

1647+
@unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction")
16391648
@unittest.skipIf(sys.platform == "win32", "doesn't make sense on Windows")
16401649
def test_missing_fd_transfer(self):
16411650
# Check that exception is raised when received data is not
@@ -1957,10 +1966,12 @@ def test_import(self):
19571966
'multiprocessing', 'multiprocessing.connection',
19581967
'multiprocessing.heap', 'multiprocessing.managers',
19591968
'multiprocessing.pool', 'multiprocessing.process',
1960-
'multiprocessing.reduction',
19611969
'multiprocessing.synchronize', 'multiprocessing.util'
19621970
]
19631971

1972+
if HAS_REDUCTION:
1973+
modules.append('multiprocessing.reduction')
1974+
19641975
if c_int is not None:
19651976
# This module requires _ctypes
19661977
modules.append('multiprocessing.sharedctypes')

0 commit comments

Comments
 (0)