hmb HF Staff commited on
Commit
6dde4ad
·
verified ·
1 Parent(s): 25b2245

Create run.py

Browse files
Files changed (1) hide show
  1. run.py +35 -0
run.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Parallel execution test for gr.Workflow.
3
+
4
+ Open in two browser tabs, type different prompts, click Run in both within
5
+ a second of each other. Check the printed timestamps:
6
+
7
+ BEFORE fix: tab 2's slow_fn starts exactly when tab 1's slow_fn ends (~16s total)
8
+ AFTER fix: both run concurrently (~8s total), timestamps overlap
9
+ """
10
+ import time
11
+ from datetime import UTC, datetime
12
+
13
+ import gradio as gr
14
+
15
+
16
+ def _now() -> str:
17
+ return datetime.now(UTC).strftime("%H:%M:%S.%f")[:-3]
18
+
19
+
20
+ def slow_fn(text: str) -> str:
21
+ start = _now()
22
+ time.sleep(5)
23
+ return f"slow | start={start} end={_now()} | input={text!r}"
24
+
25
+
26
+ def fast_fn(text: str) -> str:
27
+ start = _now()
28
+ time.sleep(2)
29
+ return f"fast | start={start} end={_now()}\n{text}"
30
+
31
+
32
+ demo = gr.Workflow(bind={"slow_fn": slow_fn, "fast_fn": fast_fn})
33
+
34
+ if __name__ == "__main__":
35
+ demo.launch()