# Exiting before cleanup is executed

**URL:** <https://discuss.ray.io/t/exiting-before-cleanup-is-executed/1046>\
**Category:** Ray Tune\
**Created:** [February 27, 2021, 4:25pm UTC](https://discuss.ray.io/t/exiting-before-cleanup-is-executed/1046 "2021-02-27T16:25:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vishnu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/vishnu/32/41_2.png) [@Vishnu](https://discuss.ray.io/u/Vishnu)\
**Post date:** [February 27, 2021, 4:25pm UTC](https://discuss.ray.io/t/exiting-before-cleanup-is-executed/1046/1 "2021-02-27T16:25:14Z")

</div>

When migrating from Ray 1.0.1 to Ray 1.1.0 or 1.2.0, I found that the program exits as soon as all the iterations are done in tune.run. The execution of the cleanup function is not fully completed.

I’ve actually faced this issue before in a previous version of Ray and @rliaw implemented a solution to fix it.

Here’s the issue I previously raised:

> <https://github.com/ray-project/ray/issues/7963>
>
> Ray version and other system information (Python version, TensorFlow version, OS):
> ray 0.8.4
> python 3.6.9
> What is the problem?
> We're using \_stop in our Trainable...

And here’s the PR that successfully fixed it:

> <https://github.com/ray-project/ray/pull/7967>

In 1.2.0, I tried adding a time.sleep call after tune.run and that helped the cleanup function complete execution.

---

<div class="post-metadata">

**Author:** ![rliaw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/rliaw/32/24_2.png) [@rliaw](https://discuss.ray.io/u/rliaw)\
**Post date:** [February 27, 2021, 8:02pm UTC](https://discuss.ray.io/t/exiting-before-cleanup-is-executed/1046/2 "2021-02-27T20:02:34Z")

</div>

uh oh… this seems odd. Could you post an issue on Github and tag me?

---

<div class="post-metadata">

**Author:** ![Vishnu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/vishnu/32/41_2.png) [@Vishnu](https://discuss.ray.io/u/Vishnu)\
**Post date:** [February 28, 2021, 6:33am UTC](https://discuss.ray.io/t/exiting-before-cleanup-is-executed/1046/3 "2021-02-28T06:33:04Z")

</div>

Of course, I’ll do that
