diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index 4b36c194cb3c3c..b96cc64f7d1772 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -33,7 +33,11 @@ HAVE_SENDMSG = hasattr(socket.socket, 'sendmsg') if HAVE_SENDMSG: - SC_IOV_MAX = os.sysconf('SC_IOV_MAX') + try: + SC_IOV_MAX = os.sysconf('SC_IOV_MAX') + except OSError: + # Fallback to send + HAVE_SENDMSG = False def _test_selector_event(selector, fd, event): # Test if the selector is monitoring 'event' events diff --git a/Lib/test/test_asyncio/test_selector_events.py b/Lib/test/test_asyncio/test_selector_events.py index b20e4bce17c27c..8075312026342b 100644 --- a/Lib/test/test_asyncio/test_selector_events.py +++ b/Lib/test/test_asyncio/test_selector_events.py @@ -1,24 +1,25 @@ """Tests for selector_events.py""" import collections -import sys import selectors import socket +import sys import unittest +from asyncio import selector_events from unittest import mock + try: import ssl except ImportError: ssl = None import asyncio -from asyncio.selector_events import BaseSelectorEventLoop -from asyncio.selector_events import _SelectorTransport -from asyncio.selector_events import _SelectorSocketTransport -from asyncio.selector_events import _SelectorDatagramTransport +from asyncio.selector_events import (BaseSelectorEventLoop, + _SelectorDatagramTransport, + _SelectorSocketTransport, + _SelectorTransport) from test.test_asyncio import utils as test_utils - MOCK_ANY = mock.ANY @@ -746,7 +747,7 @@ def test_write_sendmsg_no_data(self): self.assertFalse(self.sock.sendmsg.called) self.assertEqual(list_to_buffer([b'data']), transport._buffer) - @unittest.skipUnless(hasattr(socket.socket, 'sendmsg'), 'no sendmsg') + @unittest.skipUnless(selector_events.HAVE_SENDMSG, 'no sendmsg') def test_write_sendmsg_full(self): data = memoryview(b'data') self.sock.sendmsg = mock.Mock() @@ -759,7 +760,7 @@ def test_write_sendmsg_full(self): self.assertTrue(self.sock.sendmsg.called) self.assertFalse(self.loop.writers) - @unittest.skipUnless(hasattr(socket.socket, 'sendmsg'), 'no sendmsg') + @unittest.skipUnless(selector_events.HAVE_SENDMSG, 'no sendmsg') def test_write_sendmsg_partial(self): data = memoryview(b'data')