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

Skip to content

Commit c5fce4d

Browse files
committed
check individually for some for sched_ functions
1 parent 28da7b8 commit c5fce4d

5 files changed

Lines changed: 43 additions & 4 deletions

File tree

Lib/test/test_posix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ def test_sched_priority(self):
851851
self.assertRaises(OSError, posix.sched_get_priority_min, -23)
852852
self.assertRaises(OSError, posix.sched_get_priority_max, -23)
853853

854-
@requires_sched_h
854+
@unittest.skipUnless(hasattr(posix, 'sched_setscheduler'), "can't change scheduler")
855855
def test_get_and_set_scheduler_and_param(self):
856856
possible_schedulers = [sched for name, sched in posix.__dict__.items()
857857
if name.startswith("SCHED_")]
@@ -882,7 +882,7 @@ def test_get_and_set_scheduler_and_param(self):
882882
param = posix.sched_param(sched_priority=-large)
883883
self.assertRaises(OverflowError, posix.sched_setparam, 0, param)
884884

885-
@requires_sched_h
885+
@unittest.skipUnless(hasattr(posix, "sched_rr_get_interval"), "no function")
886886
def test_sched_rr_get_interval(self):
887887
interval = posix.sched_rr_get_interval(0)
888888
self.assertIsInstance(interval, float)

Modules/posixmodule.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4585,6 +4585,8 @@ posix_sched_get_priority_min(PyObject *self, PyObject *args)
45854585
return PyLong_FromLong(min);
45864586
}
45874587

4588+
#ifdef HAVE_SCHED_SETSCHEDULER
4589+
45884590
PyDoc_STRVAR(posix_sched_getscheduler__doc__,
45894591
"sched_getscheduler(pid)\n\n\
45904592
Get the scheduling policy for the process with a PID of *pid*.\n\
@@ -4604,6 +4606,10 @@ posix_sched_getscheduler(PyObject *self, PyObject *args)
46044606
return PyLong_FromLong(policy);
46054607
}
46064608

4609+
#endif
4610+
4611+
#if defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)
4612+
46074613
static PyObject *
46084614
sched_param_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
46094615
{
@@ -4656,6 +4662,10 @@ convert_sched_param(PyObject *param, struct sched_param *res)
46564662
return 1;
46574663
}
46584664

4665+
#endif
4666+
4667+
#ifdef HAVE_SCHED_SETSCHEDULER
4668+
46594669
PyDoc_STRVAR(posix_sched_setscheduler__doc__,
46604670
"sched_setscheduler(pid, policy, param)\n\n\
46614671
Set the scheduling policy, *policy*, for *pid*.\n\
@@ -4677,6 +4687,10 @@ posix_sched_setscheduler(PyObject *self, PyObject *args)
46774687
Py_RETURN_NONE;
46784688
}
46794689

4690+
#endif
4691+
4692+
#ifdef HAVE_SCHED_SETPARAM
4693+
46804694
PyDoc_STRVAR(posix_sched_getparam__doc__,
46814695
"sched_getparam(pid) -> sched_param\n\n\
46824696
Returns scheduling parameters for the process with *pid* as an instance of the\n\
@@ -4724,6 +4738,10 @@ posix_sched_setparam(PyObject *self, PyObject *args)
47244738
Py_RETURN_NONE;
47254739
}
47264740

4741+
#endif
4742+
4743+
#ifdef HAVE_SCHED_RR_GET_INTERVAL
4744+
47274745
PyDoc_STRVAR(posix_sched_rr_get_interval__doc__,
47284746
"sched_rr_get_interval(pid) -> float\n\n\
47294747
Return the round-robin quantum for the process with PID *pid* in seconds.");
@@ -4741,6 +4759,8 @@ posix_sched_rr_get_interval(PyObject *self, PyObject *args)
47414759
return PyFloat_FromDouble((double)interval.tv_sec + 1e-9*interval.tv_nsec);
47424760
}
47434761

4762+
#endif
4763+
47444764
PyDoc_STRVAR(posix_sched_yield__doc__,
47454765
"sched_yield()\n\n\
47464766
Voluntarily relinquish the CPU.");
@@ -10054,11 +10074,21 @@ static PyMethodDef posix_methods[] = {
1005410074
#ifdef HAVE_SCHED_H
1005510075
{"sched_get_priority_max", posix_sched_get_priority_max, METH_VARARGS, posix_sched_get_priority_max__doc__},
1005610076
{"sched_get_priority_min", posix_sched_get_priority_min, METH_VARARGS, posix_sched_get_priority_min__doc__},
10077+
#ifdef HAVE_SCHED_SETPARAM
1005710078
{"sched_getparam", posix_sched_getparam, METH_VARARGS, posix_sched_getparam__doc__},
10079+
#endif
10080+
#ifdef HAVE_SCHED_SETSCHEDULER
1005810081
{"sched_getscheduler", posix_sched_getscheduler, METH_VARARGS, posix_sched_getscheduler__doc__},
10082+
#endif
10083+
#ifdef HAVE_SCHED_RR_GET_INTERVAL
1005910084
{"sched_rr_get_interval", posix_sched_rr_get_interval, METH_VARARGS, posix_sched_rr_get_interval__doc__},
10085+
#endif
10086+
#ifdef HAVE_SCHED_SETPARAM
1006010087
{"sched_setparam", posix_sched_setparam, METH_VARARGS, posix_sched_setparam__doc__},
10088+
#endif
10089+
#ifdef HAVE_SCHED_SETSCHEDULER
1006110090
{"sched_setscheduler", posix_sched_setscheduler, METH_VARARGS, posix_sched_setscheduler__doc__},
10091+
#endif
1006210092
{"sched_yield", posix_sched_yield, METH_NOARGS, posix_sched_yield__doc__},
1006310093
#ifdef HAVE_SCHED_SETAFFINITY
1006410094
{"sched_setaffinity", posix_sched_setaffinity, METH_VARARGS, posix_sched_setaffinity__doc__},

configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9339,7 +9339,7 @@ for ac_func in alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
93399339
select sem_open sem_timedwait sem_getvalue sem_unlink sendfile setegid seteuid \
93409340
setgid sethostname \
93419341
setlocale setregid setreuid setresuid setresgid setsid setpgid setpgrp setpriority setuid setvbuf \
9342-
sched_setaffinity \
9342+
sched_setaffinity sched_setscheduler sched_setparam sched_rr_get_interval \
93439343
sigaction sigaltstack siginterrupt sigpending sigrelse \
93449344
sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy symlinkat sync \
93459345
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \

configure.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2537,7 +2537,7 @@ AC_CHECK_FUNCS(alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
25372537
select sem_open sem_timedwait sem_getvalue sem_unlink sendfile setegid seteuid \
25382538
setgid sethostname \
25392539
setlocale setregid setreuid setresuid setresgid setsid setpgid setpgrp setpriority setuid setvbuf \
2540-
sched_setaffinity \
2540+
sched_setaffinity sched_setscheduler sched_setparam sched_rr_get_interval \
25412541
sigaction sigaltstack siginterrupt sigpending sigrelse \
25422542
sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy symlinkat sync \
25432543
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \

pyconfig.h.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,18 @@
653653
/* Define to 1 if you have the <sched.h> header file. */
654654
#undef HAVE_SCHED_H
655655

656+
/* Define to 1 if you have the `sched_rr_get_interval' function. */
657+
#undef HAVE_SCHED_RR_GET_INTERVAL
658+
656659
/* Define to 1 if you have the `sched_setaffinity' function. */
657660
#undef HAVE_SCHED_SETAFFINITY
658661

662+
/* Define to 1 if you have the `sched_setparam' function. */
663+
#undef HAVE_SCHED_SETPARAM
664+
665+
/* Define to 1 if you have the `sched_setscheduler' function. */
666+
#undef HAVE_SCHED_SETSCHEDULER
667+
659668
/* Define to 1 if you have the `select' function. */
660669
#undef HAVE_SELECT
661670

0 commit comments

Comments
 (0)