MCPcopy Index your code
hub / github.com/showlab/Code2Video / get_optimal_workers

Function get_optimal_workers

src/utils.py:53–70  ·  view source on GitHub ↗

Calculate the optimal number of parallel processes adaptively based on # CPU cores and load

()

Source from the content-addressed store, hash-verified

51
52
53def get_optimal_workers():
54 """Calculate the optimal number of parallel processes adaptively based on # CPU cores and load"""
55 try:
56 cpu_count = multiprocessing.cpu_count()
57 except NotImplementedError:
58 cpu_count = 6 # default
59
60 # Manim rendering is CPU-intensive; usually set workers to CPU cores or cores minus one
61 # reserve 1 core for system/other processes
62 optimal = max(1, cpu_count - 1)
63
64 # If the machine is high-performance multicore (>16 cores),
65 # it's appropriate to limit the number of workers to avoid memory overflow
66 if optimal > 16:
67 optimal = 16
68
69 print(f"⚙️ Detected {cpu_count} cores, using {optimal} parallel processes")
70 return optimal
71
72
73def monitor_system_resources():

Callers 2

utils.pyFile · 0.85
agent.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected