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%