Skip to content

Commit 7545762

Browse files
committed
Fix error in gc and up version
1 parent 31cc438 commit 7545762

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

.gitignore

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,10 @@ dmypy.json
152152
# Cython debug symbols
153153
cython_debug/
154154

155-
# PyCharm
156-
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157-
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158-
# and can be added to the global gitignore or merged into this file. For a more nuclear
159-
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
155+
# IDEs
160156
.idea/
157+
.vscode/
158+
.cursor/
161159

162160
# Project ignores
163161
/downloads_for_van/

src/constants/app_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
APP_AUTHOR: Final[str] = "System X - Files"
88
APP_NAME: Final[str] = "Process Governor"
9-
APP_VERSION: Final[str] = "1.3.0"
9+
APP_VERSION: Final[str] = "1.3.1"
1010
APP_PROCESSES = {f"{APP_NAME}.exe", "python.exe"}
1111

1212
CURRENT_TAG: Final[str] = f"v{APP_VERSION}"

src/service/rules_service.py

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ def apply_rules(cls, config: Config, only_new: bool):
4545
return
4646

4747
cls.__light_gc_ignored_process_parameters()
48-
cls.__handle_processes(
49-
config,
50-
ProcessesInfoService.get_processes(),
51-
only_new
52-
)
48+
cls.__handle_processes(config, ProcessesInfoService.get_processes(), only_new)
5349

5450
@classmethod
55-
def __handle_processes(cls, config: Config, processes: dict[int, Process], only_new: bool):
51+
def __handle_processes(
52+
cls, config: Config, processes: dict[int, Process], only_new: bool
53+
):
5654
for pid, process in processes.items():
5755
if pid in cls.__ignore_pids:
5856
continue
5957

60-
rule: Optional[ProcessRule | ServiceRule] = cls.__first_rule_by_process(config, process)
58+
rule: Optional[ProcessRule | ServiceRule] = cls.__first_rule_by_process(
59+
config, process
60+
)
6161

6262
if not rule:
6363
continue
@@ -66,26 +66,36 @@ def __handle_processes(cls, config: Config, processes: dict[int, Process], only_
6666
continue
6767

6868
if rule.delay > 0:
69-
TaskScheduler.schedule_task(process, cls.__handle_process, process, rule, delay=rule.delay)
69+
TaskScheduler.schedule_task(
70+
process, cls.__handle_process, process, rule, delay=rule.delay
71+
)
7072
else:
7173
cls.__handle_process(process, rule)
7274

7375
@classmethod
7476
def __handle_process(cls, process: Process, rule: ProcessRule | ServiceRule):
75-
parameter_methods: dict[ProcessParameter, tuple[Callable[[Process, ProcessRule | ServiceRule], bool], str]] = {
76-
ProcessParameter.AFFINITY: (cls.__set_affinity, format_affinity(rule.affinity)),
77+
parameter_methods: dict[
78+
ProcessParameter,
79+
tuple[Callable[[Process, ProcessRule | ServiceRule], bool], str],
80+
] = {
81+
ProcessParameter.AFFINITY: (
82+
cls.__set_affinity,
83+
format_affinity(rule.affinity),
84+
),
7785
ProcessParameter.NICE: (cls.__set_nice, rule.priority),
78-
ProcessParameter.IONICE: (cls.__set_ionice, rule.ioPriority)
86+
ProcessParameter.IONICE: (cls.__set_ionice, rule.ioPriority),
7987
}
8088

8189
try:
82-
ignored_parameters = cls.__ignored_process_parameters.setdefault(process, set())
90+
ignored_parameters = cls.__ignored_process_parameters.setdefault(
91+
process, set()
92+
)
8393

8494
for param, (method, logger_value) in parameter_methods.items():
8595
if param in ignored_parameters:
8696
continue
8797

88-
service_name = f", {process.service_name}" if process.service else ''
98+
service_name = f", {process.service_name}" if process.service else ""
8999
logger_string = f"{param.value} `{logger_value}` for {process.process_name} ({process.pid}{service_name})"
90100

91101
try:
@@ -121,7 +131,9 @@ def __set_affinity(cls, process: Process, rule: ProcessRule | ServiceRule):
121131
return True
122132

123133
@classmethod
124-
def __first_rule_by_process(cls, config: Config, process: Process) -> Optional[ProcessRule | ServiceRule]:
134+
def __first_rule_by_process(
135+
cls, config: Config, process: Process
136+
) -> Optional[ProcessRule | ServiceRule]:
125137
if process.service:
126138
for rule in config.serviceRules:
127139
if path_match(rule.selector, process.service_name):
@@ -137,10 +149,10 @@ def __first_rule_by_process(cls, config: Config, process: Process) -> Optional[P
137149

138150
@classmethod
139151
def find_rules_ids_by_process(
140-
cls,
141-
process: Process,
142-
process_rules: dict[str, ProcessRule],
143-
service_rules: dict[str, ServiceRule],
152+
cls,
153+
process: Process,
154+
process_rules: dict[str, ProcessRule],
155+
service_rules: dict[str, ServiceRule],
144156
) -> list[tuple[str, ProcessRule | ServiceRule]]:
145157
result = []
146158

@@ -174,7 +186,8 @@ def _get_value_for_matching(cls, process, rule):
174186
@cached(5) # Workaround to ensure the procedure runs only once every 5 seconds
175187
def __light_gc_ignored_process_parameters(cls) -> None:
176188
pids = psutil.pids()
177-
cls._ignored_process_parameters = {
178-
key: value for key, value in cls.__ignored_process_parameters.items()
179-
if key.pid in pids
189+
# Create a copy of the items to iterate over, preventing modification issues
190+
current_items = list(cls.__ignored_process_parameters.items())
191+
cls.__ignored_process_parameters = {
192+
key: value for key, value in current_items if key.pid in pids
180193
}

0 commit comments

Comments
 (0)