Quit() takes a long time to run


#1

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


#2

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


#3

Thanks for responding.

I’d never heard of finalizers until your reply! :slight_smile: (for anyone else there is a very clear SO answer here)

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:

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()

#4

I had a similar issue with HDF5.jl:

still open.


#5

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


#6

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


#7

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

Cheers,

Colin


#8

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