Lines 1-6
Link Here
|
1 |
# Copyright 1999-2020 Gentoo Authors |
1 |
# Copyright 1999-2020 Gentoo Authors |
2 |
# Distributed under the terms of the GNU General Public License v2 |
2 |
# Distributed under the terms of the GNU General Public License v2 |
3 |
|
3 |
|
|
|
4 |
import atexit |
4 |
import collections |
5 |
import collections |
5 |
import logging |
6 |
import logging |
6 |
import operator |
7 |
import operator |
Lines 14-19
import textwrap
Link Here
|
14 |
import time |
15 |
import time |
15 |
import warnings |
16 |
import warnings |
16 |
from itertools import chain |
17 |
from itertools import chain |
|
|
18 |
from pathlib import Path |
17 |
|
19 |
|
18 |
import portage |
20 |
import portage |
19 |
portage.proxy.lazyimport.lazyimport(globals(), |
21 |
portage.proxy.lazyimport.lazyimport(globals(), |
Lines 2632-2644
def apply_priorities(settings):
Link Here
|
2632 |
nice(settings) |
2634 |
nice(settings) |
2633 |
|
2635 |
|
2634 |
def nice(settings): |
2636 |
def nice(settings): |
2635 |
try: |
2637 |
autogroup_file = Path("/proc/self/autogroup") |
2636 |
os.nice(int(settings.get("PORTAGE_NICENESS", "0"))) |
2638 |
|
2637 |
except (OSError, ValueError) as e: |
2639 |
nice_value : str = settings.get("PORTAGE_NICENESS", "0") |
2638 |
out = portage.output.EOutput() |
2640 |
|
2639 |
out.eerror("Failed to change nice value to '%s'" % \ |
2641 |
if not autogroup_file.is_file(): |
2640 |
settings.get("PORTAGE_NICENESS", "0")) |
2642 |
# Autogroup scheduling is not enabled on this system, |
2641 |
out.eerror("%s\n" % str(e)) |
2643 |
# continue using good ol' os.nice(). |
|
|
2644 |
try: |
2645 |
os.nice(int(nice_value)) |
2646 |
except (OSError, ValueError) as e: |
2647 |
out = portage.output.EOutput() |
2648 |
out.eerror("Failed to change nice value to '%s'" % \ |
2649 |
settings.get("PORTAGE_NICENESS", "0")) |
2650 |
out.eerror("%s\n" % str(e)) |
2651 |
return |
2652 |
|
2653 |
with autogroup_file.open('r+') as f: |
2654 |
line = f.readline() |
2655 |
original_autogroup_nice_value = line.split(' ')[2] |
2656 |
|
2657 |
# We need to restore the original nice value of the |
2658 |
# autogroup, as otherwise the session, e.g. the |
2659 |
# terminal where protage was executed in, would |
2660 |
# continue running with that value. |
2661 |
atexit.register( |
2662 |
lambda value: autogroup_file.open('w').write(value), |
2663 |
original_autogroup_nice_value |
2664 |
) |
2665 |
|
2666 |
try: |
2667 |
f.write(nice_value) |
2668 |
except (OSError) as e: |
2669 |
out = portage.output.EOutput() |
2670 |
out.eerror("Failed to change nice value to '%s'" % \ |
2671 |
settings.get("PORTAGE_NICENESS", "0")) |
2672 |
out.eerror("%s\n" % str(e)) |
2673 |
|
2642 |
|
2674 |
|
2643 |
def ionice(settings): |
2675 |
def ionice(settings): |
2644 |
|
2676 |
|
2645 |
- |
|
|