# Quit() takes a long time to run

**URL:** <https://discourse.julialang.org/t/quit-takes-a-long-time-to-run/6646>\
**Category:** General Usage\
**Created:** [October 24, 2017, 5:29am UTC](https://discourse.julialang.org/t/quit-takes-a-long-time-to-run/6646 "2017-10-24T05:29:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![colintbowers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/colintbowers/32/8033_2.png) [@colintbowers](https://discourse.julialang.org/u/colintbowers)\
**Post date:** [October 24, 2017, 5:29am UTC](https://discourse.julialang.org/t/quit-takes-a-long-time-to-run/6646/1 "2017-10-24T05:29:54Z")

</div>

Hi all,

Julia v0.6 on Ubuntu 16.04 LTS.

Does anyone know why `quit()` would take a long time to execute? By “long-time” I mean many minutes, with one CPU running at 100%.

I haven’t been able to isolate a MWE yet, since it only happens after running long routines that involve lots of reading and heavy computation. I’ll keep working on the MWE, but thought I would ask here in the meantime, since some clues might help me to isolate what is happening.

Cheers,

Colin

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 24, 2017, 8:04am UTC](https://discourse.julialang.org/t/quit-takes-a-long-time-to-run/6646/2 "2017-10-24T08:04:46Z")

</div>

An MWE would be useful. My first suspect would be finalizers — check your code or the packages you use for finalizers, or `atexit(...)` hooks.

---

<div class="post-metadata">

**Author:** ![colintbowers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/colintbowers/32/8033_2.png) [@colintbowers](https://discourse.julialang.org/u/colintbowers)\
**Post date:** [October 24, 2017, 9:32am UTC](https://discourse.julialang.org/t/quit-takes-a-long-time-to-run/6646/3 "2017-10-24T09:32:39Z")

</div>

Thanks for responding.

I’d never heard of finalizers until your reply! 🙂 (for anyone else there is a very clear [SO answer here](https://stackoverflow.com/questions/38292448/what-does-it-mean-to-finalize-in-julia))

The code in question does, at one point, do the following:

```
y = parse(x)
typeof(y) != Symbol && error("x string did not parse to symbol")
z = eval(y)
!(z <: SomeAbstractType) && error("x string did not eval to expected type")

```

and then later it calls:

```
z(input)

```

which will therefore call an outer constructor for some subtype of `SomeAbstractType`.

This pattern is looped over many thousands of times (for thousands of different datasets).

Could this be causing the issue?

I tried the following MWE, but it didn’t have any problems:

```julia
mutable struct M ; x::Vector{Float64} ; end
M()::M = M(randn(100))
N = 1000000
f(y::String) = eval(parse(y))()
g(strvec::Vector{String}) = [f(y) for y in strvec]
strvec = ["M" for n = 1:N]
g(strvec)
quit()

```

---

<div class="post-metadata">

**Author:** ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)\
**Post date:** [October 24, 2017, 11:21am UTC](https://discourse.julialang.org/t/quit-takes-a-long-time-to-run/6646/4 "2017-10-24T11:21:20Z")

</div>

I had a similar issue with HDF5.jl:

[https://github.com/JuliaIO/HDF5.jl/issues/413](https://github.com/JuliaIO/HDF5.jl/issues/413)

still open.

---

<div class="post-metadata">

**Author:** ![colintbowers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/colintbowers/32/8033_2.png) [@colintbowers](https://discourse.julialang.org/u/colintbowers)\
**Post date:** [October 24, 2017, 11:40am UTC](https://discourse.julialang.org/t/quit-takes-a-long-time-to-run/6646/5 "2017-10-24T11:40:57Z")

</div>

That sounds like a possible culprit. My code in question uses HDF5.jl for all reading operations (and there are thousands of them). I’ll do a little more testing tomorrow and if I can add anything useful to the issue I will.

Thanks for responding.

Colin

---

<div class="post-metadata">

**Author:** ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)\
**Post date:** [October 24, 2017, 11:47am UTC](https://discourse.julialang.org/t/quit-takes-a-long-time-to-run/6646/6 "2017-10-24T11:47:51Z")

</div>

yes this is exactly how I do it. There is a workaround: Open the HDF5 handle only once and not on every file read.

---

<div class="post-metadata">

**Author:** ![colintbowers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/colintbowers/32/8033_2.png) [@colintbowers](https://discourse.julialang.org/u/colintbowers)\
**Post date:** [October 24, 2017, 11:46pm UTC](https://discourse.julialang.org/t/quit-takes-a-long-time-to-run/6646/7 "2017-10-24T23:46:37Z")

</div>

Found the problem. It is the same one described by tobias.knopp.

Cheers,

Colin

---

<div class="post-metadata">

**Author:** ![colintbowers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/colintbowers/32/8033_2.png) [@colintbowers](https://discourse.julialang.org/u/colintbowers)\
**Post date:** [October 24, 2017, 11:51pm UTC](https://discourse.julialang.org/t/quit-takes-a-long-time-to-run/6646/8 "2017-10-24T23:51:45Z")

</div>

Yes, this was the problem. I isolated the reads, and observed the same long wait on `quit()`.

Unfortunately in my situation the workaround is not straightforward since the calls to `h5read` are a long way inside the program and are looped over at a much higher level. I suppose I could use a globally defined handle…

I think for now I’ll just use the “other” workaround (when I’m finished with julia I just kill the terminal it is running in).

Cheers, and thanks for your help.

Colin
