Skip to content

Commit c704222

Browse files
authored
closes bpo-34650: Check if sched_getscheduler returns ENOSYS before declaring it supported. (GH-9228)
musl doesn't support the scheduler API, but declares stubs that alway return ENOSYS.
1 parent 6f82bff commit c704222

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Lib/test/test_posix.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
requires_32b = unittest.skipUnless(sys.maxsize < 2**32,
2626
'test is only meaningful on 32-bit builds')
2727

28+
def _supports_sched():
29+
if not hasattr(posix, 'sched_getscheduler'):
30+
return False
31+
try:
32+
posix.sched_getscheduler(0)
33+
except OSError as e:
34+
if e.errno == errno.ENOSYS:
35+
return False
36+
return True
37+
38+
requires_sched = unittest.skipUnless(_supports_sched(), 'requires POSIX scheduler API')
39+
2840
class PosixTester(unittest.TestCase):
2941

3042
def setUp(self):
@@ -1273,7 +1285,7 @@ def test_sched_priority(self):
12731285
self.assertRaises(OSError, posix.sched_get_priority_min, -23)
12741286
self.assertRaises(OSError, posix.sched_get_priority_max, -23)
12751287

1276-
@unittest.skipUnless(hasattr(posix, 'sched_setscheduler'), "can't change scheduler")
1288+
@requires_sched
12771289
def test_get_and_set_scheduler_and_param(self):
12781290
possible_schedulers = [sched for name, sched in posix.__dict__.items()
12791291
if name.startswith("SCHED_")]
@@ -1646,7 +1658,7 @@ def test_setsigdef_wrong_type(self):
16461658
[sys.executable, "-c", "pass"],
16471659
os.environ, setsigdef=[signal.NSIG, signal.NSIG+1])
16481660

1649-
@unittest.skipUnless(hasattr(posix, 'sched_setscheduler'), "can't change scheduler")
1661+
@requires_sched
16501662
def test_setscheduler_only_param(self):
16511663
policy = os.sched_getscheduler(0)
16521664
priority = os.sched_get_priority_min(policy)
@@ -1664,7 +1676,7 @@ def test_setscheduler_only_param(self):
16641676
)
16651677
self.assertEqual(os.waitpid(pid, 0), (pid, 0))
16661678

1667-
@unittest.skipUnless(hasattr(posix, 'sched_setscheduler'), "can't change scheduler")
1679+
@requires_sched
16681680
def test_setscheduler_with_policy(self):
16691681
policy = os.sched_getscheduler(0)
16701682
priority = os.sched_get_priority_min(policy)

0 commit comments

Comments
 (0)