Skip to content

Commit eff72f9

Browse files
committed
[3.7] 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.. (cherry picked from commit c704222) Co-authored-by: Benjamin Peterson <benjamin@python.org>
1 parent ec4d099 commit eff72f9

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

Lib/test/test_posix.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@
2323
requires_32b = unittest.skipUnless(sys.maxsize < 2**32,
2424
'test is only meaningful on 32-bit builds')
2525

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

2840
def setUp(self):
@@ -1276,7 +1288,7 @@ def test_sched_priority(self):
12761288
self.assertRaises(OSError, posix.sched_get_priority_min, -23)
12771289
self.assertRaises(OSError, posix.sched_get_priority_max, -23)
12781290

1279-
@unittest.skipUnless(hasattr(posix, 'sched_setscheduler'), "can't change scheduler")
1291+
@requires_sched
12801292
def test_get_and_set_scheduler_and_param(self):
12811293
possible_schedulers = [sched for name, sched in posix.__dict__.items()
12821294
if name.startswith("SCHED_")]

0 commit comments

Comments
 (0)