How to stop the worker when the process (client) finished?

original_loop = asyncio.get_event_loop()

original_loop = asyncio.get_running_loop()

worker.include_router(router)
original_loop.run_until_complete(work_run(worker))

I use the loop to make the worker start work but when the instance is completed, the worker will not be stopped, which means the python file will be executed forever if I don’t stop it.

Hey @Yinshen_Tao!
Why would you want to stop the worker? :thinking:
Keep in mind that if you stop it it won’t fetch any new tasks and would not recognise when a new process instance is started on.

A possible solution for this problem depends on the process looks like.
You could call the Zeebe API to check the status of your process instance so. In case it is completed you could should the worker down by itself.

Though I have not done so in Python yet…

what I think is when the process finishes, the worker needs to stop because I want to do the external tasks and get the final result from the camunda. If I create the worker and client in one system, I can’t get the final result due to the worker working continuously.

The worker doesn’t process just one instance, it will keep doing the work it is built to do.
Think of the process like an assembly line… The outcome of building a particular car (either passing inspection or not passing inspection) doesn’t stop the worker from building the next car.

Camunda doesn’t really “give a final result” (though you might want to look at DMN evaluation if you’re looking for decision results). Camunda processes run until they are complete. You would need to look at the name of the “End Process” step to determine why it ended.

Also… find the error in the above process :smiley: