import ash_flare as af
import time
execution_log = []
def make_worker(worker_id, duration):
def worker_fn():
execution_log.append(f"{worker_id} started")
time.sleep(duration)
execution_log.append(f"{worker_id} completed")
return worker_fn
def main():
print("=== Simple Worker Test - Python Code Execution ===\n")
spec = af.SupervisorSpec("test-supervisor")
spec.with_restart_strategy(af.RestartStrategy.one_for_one())
for i in range(5):
worker_id = f"worker-{i}"
duration = 1 worker_fn = make_worker(worker_id, duration)
spec.add_worker(worker_id, af.RestartPolicy.temporary(), worker_fn)
print("Starting supervisor with 5 workers...")
handle = af.SupervisorHandle.start(spec)
time.sleep(3)
print("\nExecution log:")
for entry in execution_log:
print(f" {entry}")
print(f"\nTotal executions logged: {len(execution_log)}")
print("✓ Python code was executed successfully in workers!")
handle.shutdown()
if __name__ == "__main__":
main()