Get the number of CPU cores available or the current CPU affinity.
()
| 495 | |
| 496 | |
| 497 | def get_cpu_affinity_or_count_fallback() -> int: |
| 498 | """Get the number of CPU cores available or the current CPU affinity.""" |
| 499 | if platform.system() in ("Linux", "Windows"): |
| 500 | try: |
| 501 | return len(psutil.Process().cpu_affinity()) |
| 502 | except Exception: |
| 503 | return os.cpu_count() or 4 |
| 504 | return os.cpu_count() or 4 |
| 505 | |
| 506 | |
| 507 | def set_memory_binding(node: Optional[int]) -> None: |