Nivel 88: demo_level88.pyο
Este es el nivel 88 del tour de aprendizaje.
CΓ³digo Fuenteο
"""
DEMO LEVEL 88: ResourceMonitor en Bucle
-------------------------------------
Adds: Monitoreo en mΓΊltiples ejecuciones.
Continues: L87.
DIAGRAM:
for i in range(3): ResourceMonitor()
"""
import time
from wpipe import Pipeline, ResourceMonitor, step
@step(name="task")
def task(data: dict) -> None:
"""Task step.
Args:
data: Input data for the step.
Returns:
dict: Result of the step.
"""
time.sleep(0.02)
return {"ok": True}
if __name__ == "__main__":
print(">>> MΓΊltiples ejecuciones...")
with ResourceMonitor("Viaje_L88") as monitor:
for i in range(3):
pipe = Pipeline(pipeline_name=f"Viaje_L88_{i}", verbose=False)
pipe.set_steps([task])
pipe.run({})
print(f" β
iteraciΓ³n {i}")
summary = monitor.get_summary()
print(f"\nπ Total 3 ejecuciones:")
print(f" Peak RAM: {summary['peak_ram_mb']:.1f} MB")
print(f" Avg CPU: {summary['avg_cpu_percent']:.1f}%")
Resultado de EjecuciΓ³nο
>>> MΓΊltiples ejecuciones... Viaje_L88_0 ββββββββββββββββββββββββββββββββββββββββ 100% 0:00:00 β iteraciΓ³n 0 Viaje_L88_0 ββββββββββββββββββββββββββββββββββββββββ 100% 0:00:00 Viaje_L88_1 ββββββββββββββββββββββββββββββββββββββββ 100% 0:00:00 β iteraciΓ³n 1 Viaje_L88_0 ββββββββββββββββββββββββββββββββββββββββ 100% 0:00:00 Viaje_L88_1 ββββββββββββββββββββββββββββββββββββββββ 100% 0:00:00 Viaje_L88_2 ββββββββββββββββββββββββββββββββββββββββ 100% 0:00:00 β iteraciΓ³n 2
- π Total 3 ejecuciones:
Peak RAM: 49.4 MB Avg CPU: 14.3%