Plots.jl: GKS file open error: Too many open files

Created on 5 Sep 2018  路  6Comments  路  Source: JuliaPlots/Plots.jl

Generating many plots and saving them leads to an "Too many open files" error using the GR backend. I could not find any information on how to close a plot/file in the documentation. A minimal working example:

using Plots                                                                     

function mkplot(it)                                                             
  p = plot(1:it)                                                                

  numb = lpad(it,3,'0')                                                         
  fname = "plot_$(numb).png"                                                    

  println(fname)                                                                
  savefig(p,fname)                                                              
end                                                                             


for i=1:1000                                                                    
  mkplot(i)                                                                     
end                                                                             

I figured that the plot object should go out of scope and therefore be garbage collected if necessary. But is there any explicit way to close the plot/file?
"closeall()" did not work.
The error was raised for plot_514.png for me:

[..]
plot_504.png
plot_505.png
plot_506.png
plot_507.png
plot_508.png
plot_509.png
plot_510.png
plot_511.png
GKS: file open error (/home/hslxrsrv3/stnv053/.julia/packages/GR/ztzRc/src/../deps/gr/fonts/gksfont.dat)
open: Too many open files
plot_512.png
plot_513.png
plot_514.png
socket: Too many open files
GKS: can't connect to GKS socket application
Did you start 'gksqt'?

GKS: Open failed in routine OPEN_WS
GKS: GKS not in proper state. GKS must be either in the state WSOP or WSAC in routine ACTIVATE_WS
GKS: file open error (/tmp/juliadXi2wN.png)
open: Too many open files
ERROR: LoadError: SystemError: opening file /tmp/juliadXi2wN.png: No such file or directory
Stacktrace:
 [1] #systemerror#39(::Nothing, ::Function, ::String, ::Bool) at ./error.jl:106
 [2] systemerror at ./error.jl:106 [inlined]
 [3] #open#293(::Nothing, ::Nothing, ::Nothing, ::Nothing, ::Nothing, ::Function, ::String) at ./iostream.jl:283
 [4] open at ./iostream.jl:275 [inlined]
 [5] #open#294(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::getfield(Base, Symbol("##258#259")){String}, ::String) at ./iostream.jl:367
 [6] open at ./iostream.jl:367 [inlined]
 [7] read at ./io.jl:297 [inlined]
 [8] _show(::IOStream, ::MIME{Symbol("image/png")}, ::Plots.Plot{Plots.GRBackend}) at /home/hslxrsrv3/stnv053/.julia/packages/Plots/MnXMC/src/backends/gr.jl:1398
 [9] show(::IOStream, ::MIME{Symbol("image/png")}, ::Plots.Plot{Plots.GRBackend}) at /home/hslxrsrv3/stnv053/.julia/packages/Plots/MnXMC/src/output.jl:201
 [10] png(::Plots.Plot{Plots.GRBackend}, ::String) at /home/hslxrsrv3/stnv053/.julia/packages/Plots/MnXMC/src/output.jl:8
 [11] savefig(::Plots.Plot{Plots.GRBackend}, ::String) at /home/hslxrsrv3/stnv053/.julia/packages/Plots/MnXMC/src/output.jl:123
 [12] mkplot(::Int64) at /hs/ws01/scratch/stnv053/julia/bug/test.jl:10
 [13] top-level scope at /hs/ws01/scratch/stnv053/julia/bug/test.jl:15 [inlined]
 [14] top-level scope at ./none:0
 [15] include at ./boot.jl:317 [inlined]
 [16] include_relative(::Module, ::String) at ./loading.jl:1038
 [17] include(::Module, ::String) at ./sysimg.jl:29
 [18] exec_options(::Base.JLOptions) at ./client.jl:229
 [19] _start() at ./client.jl:421
in expression starting at /hs/ws01/scratch/stnv053/julia/bug/test.jl:14

Thanks!

Most helpful comment

It seems that setting GR.inline("png") is a legit workaround (I found it here: https://github.com/jheinen/GR.jl/issues/172). I made a quick test and successfully produced 100000 plots within a few minutes, without any errors.

All 6 comments

Have the same problem when generating several animations that, in total represent 1000s of frames.

Julia Version 0.7.0
Commit a4cb80f3ed (2018-08-08 06:46 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Xeon(R) CPU E5-2698 v3 @ 2.30GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.0 (ORCJIT, haswell)

Same problem after generating 1000 frames of animation with Julia1.1, Plots v0.23.0, GR v0.37.0, Ubuntu 18.04

Yep, I have the same problem running a Julia script in background and producing plots. After a few hours (not sure how many iterations) I get a similar error.

Are there any workarounds? I have difficulties getting the PyPlot backend running on our old monitoring machine with Scientific Linux 6...

It seems that setting GR.inline("png") is a legit workaround (I found it here: https://github.com/jheinen/GR.jl/issues/172). I made a quick test and successfully produced 100000 plots within a few minutes, without any errors.

It seems that setting GR.inline("png") is a legit workaround (I found it here: jheinen/GR.jl#172). I made a quick test and successfully produced 100000 plots within a few minutes, without any errors.

I had the same error generating a number of plots in a slurm cluster and I can confirm that adding GR.inline("png") solved the problem

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PallHaraldsson picture PallHaraldsson  路  4Comments

kleinschmidt picture kleinschmidt  路  3Comments

lstagner picture lstagner  路  5Comments

nebuta picture nebuta  路  3Comments

crstnbr picture crstnbr  路  3Comments