Spaces:
Running
Running
File size: 854 Bytes
6dde4ad | 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 | """
Parallel execution test for gr.Workflow.
Open in two browser tabs, type different prompts, click Run in both within
a second of each other. Check the printed timestamps:
BEFORE fix: tab 2's slow_fn starts exactly when tab 1's slow_fn ends (~16s total)
AFTER fix: both run concurrently (~8s total), timestamps overlap
"""
import time
from datetime import UTC, datetime
import gradio as gr
def _now() -> str:
return datetime.now(UTC).strftime("%H:%M:%S.%f")[:-3]
def slow_fn(text: str) -> str:
start = _now()
time.sleep(5)
return f"slow | start={start} end={_now()} | input={text!r}"
def fast_fn(text: str) -> str:
start = _now()
time.sleep(2)
return f"fast | start={start} end={_now()}\n{text}"
demo = gr.Workflow(bind={"slow_fn": slow_fn, "fast_fn": fast_fn})
if __name__ == "__main__":
demo.launch()
|