How do I stop a Python Ray Cluster

Viewed 4603

I've been looking through the documentation, and I can't find any way to stop Ray after an answer is calculated within a tolerance level. Right now I'm writing the answer to a csv with a print('Ok to stop'), and then I kill the process manually. I'd like to stop all of the workers, and then have it automatically move on to another problem. Is there an error that I can raise that will make all of the workers stop?

Thanks.

3 Answers

If you start a ray cluster with ray.init, the cluster should be killed when your python program exists. If you start it with ray start, you can use the ray stop command to shutdown the cluster. You can also use ray stop --force to forcefully kill all processes left.

To stop a Ray cluster from Python, you can use ray.shutdown().

Have a line in your Python code to break the process if a condition is met and then shutdown your Ray instance:

ray.init()

....
if tolerance_level > 50:
    break

ray.shutdown()
Related