-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_threading.py
More file actions
46 lines (34 loc) · 1.23 KB
/
test_threading.py
File metadata and controls
46 lines (34 loc) · 1.23 KB
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
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
"""
Quick threading test to verify Event() behavior
"""
import threading
import time
print("Testing threading.Event() behavior...")
wake_event = threading.Event()
def listener_thread():
"""Simulates the listener thread"""
time.sleep(2) # Simulate waiting
print("[Listener] Detected wake word, setting event...", flush=True)
wake_event.set()
print("[Listener] Event set successfully!", flush=True)
def orchestrator_thread():
"""Simulates the orchestrator thread"""
print("[Orchestrator] Waiting for wake word...", flush=True)
print(f"[Orchestrator] Event state before wait: {wake_event.is_set()}", flush=True)
wake_event.wait()
print("[Orchestrator] Wake word received!", flush=True)
wake_event.clear()
print("[Orchestrator] Done!", flush=True)
# Start both threads
listener = threading.Thread(target=listener_thread, daemon=True)
orchestrator = threading.Thread(target=orchestrator_thread, daemon=True)
listener.start()
orchestrator.start()
# Wait for both to complete
listener.join(timeout=5)
orchestrator.join(timeout=5)
if orchestrator.is_alive():
print("❌ FAILED: Orchestrator thread is still blocked!")
else:
print("✅ SUCCESS: Threading works correctly!")