File: examples/agents/langgraph/46_crash_and_resume.py
Symptom: Run it and press Enter at "Press Enter to resume (restart workers)". Instead of resuming, each spawned worker re-executes the script from the top and multiprocessing aborts:
Phase 2: Restart serve() — workers reconnect automatically
Started 3 TaskRunner process(es)
============================================================
Phase 1: Deploy + start, then simulate crash <- the child re-running the script
============================================================
Agent deployed to server.
Execution started: 11aff380-1819-4e44-a786-f92213811bcc <- a new execution, from a worker
...
RuntimeError: An attempt has been made to start a new process before the current
process has finished its bootstrapping phase ... "Safe importing of main module"
Cause: The script's body runs at module level — print(...) and runtime.serve(...) from line 109 onward — with no if __name__ == "__main__": guard. Worker processes are spawned with the spawn start method, so each child re-imports the main module and re-runs everything, including deploy and execute.
Fix: Wrap the module-level body in if __name__ == "__main__":, as every other example in the corpus does.
Verify: Run it, press Enter at the prompt, and the stalled execution resumes and completes with no RuntimeError and no second execution id.
Note: Without the fix the example demonstrates the opposite of its lesson: it is meant to show that workers reconnect and pick up a stalled workflow, and instead it starts a fresh one and crashes.
File:
examples/agents/langgraph/46_crash_and_resume.pySymptom: Run it and press Enter at "Press Enter to resume (restart workers)". Instead of resuming, each spawned worker re-executes the script from the top and multiprocessing aborts:
Cause: The script's body runs at module level —
print(...)andruntime.serve(...)from line 109 onward — with noif __name__ == "__main__":guard. Worker processes are spawned with the spawn start method, so each child re-imports the main module and re-runs everything, including deploy and execute.Fix: Wrap the module-level body in
if __name__ == "__main__":, as every other example in the corpus does.Verify: Run it, press Enter at the prompt, and the stalled execution resumes and completes with no
RuntimeErrorand no second execution id.Note: Without the fix the example demonstrates the opposite of its lesson: it is meant to show that workers reconnect and pick up a stalled workflow, and instead it starts a fresh one and crashes.