Skip to main content

Continue-As-New - Python SDK

How to Continue-As-New using the Temporal Python SDK.

Continue-As-New enables a Workflow Execution to close successfully and create a new Workflow Execution in a single atomic operation if the number of Events in the Event History is becoming too large. The Workflow Execution spawned from the use of Continue-As-New has the same Workflow Id, a new Run Id, and a fresh Event History and is passed all the appropriate parameters.

To Continue-As-New in Python, call the continue_as_new() function from inside your Workflow, which will stop the Workflow immediately and Continue-As-New.

View the source code

in the context of the rest of the application code.

# ...
@workflow.defn
class LoopingWorkflow:
@workflow.run
async def run(self, iteration: int) -> None:
if iteration == 5:
return
await asyncio.sleep(10)
workflow.continue_as_new(iteration + 1)