From 3cb4dd33c47a8f1de407a2eb847777a93ec7deb9 Mon Sep 17 00:00:00 2001 From: Brendan Lyons Date: Fri, 26 Jul 2024 00:39:19 -0700 Subject: [PATCH] try-catch to prevent closed channel error --- src/io.jl | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/io.jl b/src/io.jl index de3eb59..9e03da1 100644 --- a/src/io.jl +++ b/src/io.jl @@ -192,18 +192,28 @@ function readg(gfile; set_time=nothing) zlim = [0.0] end - for i ∈ 1:3 + local rhovn + try + for i ∈ 1:3 + if !eof(f) + xdum = take!(token) + end + end + if !eof(f) + rhovn = read_array(token,nw) + else + rhovn = zeros(nw) + end if !eof(f) xdum = take!(token) end - end - if !eof(f) - rhovn = read_array(token,nw) - else - rhovn = zeros(nw) - end - if !eof(f) - xdum = take!(token) + catch e + if isa(e, InvalidStateException) + # InvalidStateException when Channel is closed + rhovn = zeros(nw) + else + rethrow(e) + end end close(f)