mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-115596: Fix ProgramPriorityTests in test_os permanently changing the process priority (GH-115610)
This commit is contained in:
parent
437924465d
commit
90dd653a61
2 changed files with 17 additions and 16 deletions
|
@ -3506,23 +3506,22 @@ class ProgramPriorityTests(unittest.TestCase):
|
||||||
"""Tests for os.getpriority() and os.setpriority()."""
|
"""Tests for os.getpriority() and os.setpriority()."""
|
||||||
|
|
||||||
def test_set_get_priority(self):
|
def test_set_get_priority(self):
|
||||||
|
|
||||||
base = os.getpriority(os.PRIO_PROCESS, os.getpid())
|
base = os.getpriority(os.PRIO_PROCESS, os.getpid())
|
||||||
os.setpriority(os.PRIO_PROCESS, os.getpid(), base + 1)
|
code = f"""if 1:
|
||||||
try:
|
import os
|
||||||
new_prio = os.getpriority(os.PRIO_PROCESS, os.getpid())
|
os.setpriority(os.PRIO_PROCESS, os.getpid(), {base} + 1)
|
||||||
# nice value cap is 19 for linux and 20 for FreeBSD
|
print(os.getpriority(os.PRIO_PROCESS, os.getpid()))
|
||||||
if base >= 19 and new_prio <= base:
|
"""
|
||||||
raise unittest.SkipTest("unable to reliably test setpriority "
|
|
||||||
"at current nice level of %s" % base)
|
# Subprocess inherits the current process' priority.
|
||||||
else:
|
_, out, _ = assert_python_ok("-c", code)
|
||||||
self.assertEqual(new_prio, base + 1)
|
new_prio = int(out)
|
||||||
finally:
|
# nice value cap is 19 for linux and 20 for FreeBSD
|
||||||
try:
|
if base >= 19 and new_prio <= base:
|
||||||
os.setpriority(os.PRIO_PROCESS, os.getpid(), base)
|
raise unittest.SkipTest("unable to reliably test setpriority "
|
||||||
except OSError as err:
|
"at current nice level of %s" % base)
|
||||||
if err.errno != errno.EACCES:
|
else:
|
||||||
raise
|
self.assertEqual(new_prio, base + 1)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(os, 'sendfile'), "test needs os.sendfile()")
|
@unittest.skipUnless(hasattr(os, 'sendfile'), "test needs os.sendfile()")
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix ``ProgramPriorityTests`` in ``test_os`` permanently changing the process
|
||||||
|
priority.
|
Loading…
Add table
Add a link
Reference in a new issue