# Save data from interrupted computation

**URL:** <https://discourse.julialang.org/t/save-data-from-interrupted-computation/25232>\
**Category:** New to Julia\
**Created:** [June 13, 2019, 8:57am UTC](https://discourse.julialang.org/t/save-data-from-interrupted-computation/25232 "2019-06-13T08:57:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [June 13, 2019, 8:57am UTC](https://discourse.julialang.org/t/save-data-from-interrupted-computation/25232/1 "2019-06-13T08:57:57Z")

</div>

Hi,

I have a sophisticated computation that I would like to halt. The function is like the one below. If I stop the function, I lose the result `output`. Apart from rewriting the function (it is part of a package…), is there a tool (macro…) to access the local variable `output` in the function?

Thank you for your suggestions,

Best regards

```julia

function solve()
   while condition
      update!(output)
  end
  return output
end

```

---

<div class="post-metadata">

**Author:** ![bernhard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernhard/32/2619_2.png) [@bernhard](https://discourse.julialang.org/u/bernhard)\
**Post date:** [June 13, 2019, 10:44am UTC](https://discourse.julialang.org/t/save-data-from-interrupted-computation/25232/2 "2019-06-13T10:44:34Z")

</div>

What if you make output a global variable?  
In that case it should be available after the interruption (I think).

Alternatively (this is not necessarily very elegant) you could maybe store it somewhere after each update. Depending on the form of output this could be done by JLD, HDF5, writedlm, …  
Of course things may go wrong if you interrupt while saving

EDIT: if interrupting the function during the ‘save’ process creates an issue (i.e. the save takes a long time), maybe you could alternate between two save files in order to assure that at least one of them is valid (i.e. is not affected by the interrupt)

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [June 13, 2019, 12:08pm UTC](https://discourse.julialang.org/t/save-data-from-interrupted-computation/25232/3 "2019-06-13T12:08:22Z")

</div>

> [@bernhard](#):
>
> you could maybe store it somewhere after each update.

That’s probably the easiest to do indeed
