-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject_data.py
More file actions
62 lines (49 loc) · 1.8 KB
/
project_data.py
File metadata and controls
62 lines (49 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import math
from typing import Tuple
import psutil
from PySide6.QtCore import Signal
class ProjectData:
_physical_cores = None
_logical_cores = None
search_depth:int = 4000
snippet_size:int = 250
default_search_path = ""
language = "Deutsch"
@classmethod
def set_language(cls, language):
cls.language = language
@classmethod
def set(cls, search_depth, snippet_size, default_search_path, language):
cls.search_depth = int(search_depth)
cls.snippet_size = int(snippet_size)
cls.default_search_path = default_search_path
cls.language = language
@classmethod
def _get_physical_and_logical_cores(cls) -> Tuple[int, int]:
"""Gibt Tuple (physische, logische) Kerne zurück"""
if cls._physical_cores is not None and cls._logical_cores is not None:
return cls._physical_cores, cls._logical_cores
phys = psutil.cpu_count(logical=False)
logical = psutil.cpu_count(logical=True) or 1
cls._physical_cores = phys
cls._logical_cores = logical
return phys, logical
@classmethod
def get_process_cores(cls) -> int:
"""Gibt die Anzahl der CPU-Kerne für Prozesse zurück (physisch bevorzugt)"""
physical_cores, logical_cores = cls._get_physical_and_logical_cores()
process_cores = 1
if physical_cores is not None:
process_cores = physical_cores
elif logical_cores is not None:
process_cores = logical_cores
return process_cores
@classmethod
def get_used_cores(cls):
"""80% der verfügbaren Cores nutzen, mindestens 1"""
used = math.floor(cls.get_process_cores() * 0.8)
used = 1 if used < 1 else used
return used
@classmethod
def get_threads_count(cls):
return 4