Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fld_write tests fail on windows #58

Closed
JeffFessler opened this issue Jul 15, 2020 · 3 comments
Closed

fld_write tests fail on windows #58

JeffFessler opened this issue Jul 15, 2020 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@JeffFessler
Copy link
Owner

some problem with open/close/rm.
here is part of the output from unittest.
as a workaround i will just disable the test on windows for now.

fld-write.jl: Error During Test at D:\a\MIRT.jl\MIRT.jl\test\io\fld-write.jl:65
  Test threw exception
  Expression: fld_write_test1(file, data, endian = endian, raw = raw, check = true, chat = false)
  "file C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\jl_rA3SWj\\fld-write-test.raw exists"
  Stacktrace:
   [1] fld_write(::String, ::Array{UInt8,1}; check::Bool, dir::String, endian::Symbol, head::Array{String,1}, raw::Bool) at D:\a\MIRT.jl\MIRT.jl\src\io\fld-write.jl:63
   [2] #_args_and_call#25 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\Test\src\Test.jl:1293 [inlined]
   [3] fld_write_test1(::String, ::Array{UInt8,1}; raw::Bool, chat::Bool, kwarg::Base.Iterators.Pairs{Symbol,Any,Tuple{Symbol,Symbol},NamedTuple{(:endian, :check),Tuple{Symbol,Bool}}}) at D:\a\MIRT.jl\MIRT.jl\test\io\fld-write.jl:41
   [4] top-level scope at D:\a\MIRT.jl\MIRT.jl\test\io\fld-write.jl:65
   [5] include(::String) at .\client.jl:439
   [6] macro expansion at D:\a\MIRT.jl\MIRT.jl\test\io\z-test.jl:16 [inlined]
   [7] macro expansion at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\Test\src\Test.jl:1113 [inlined]
   [8] top-level scope at D:\a\MIRT.jl\MIRT.jl\test\io\z-test.jl:16
  
fld-write.jl: Error During Test at D:\a\MIRT.jl\MIRT.jl\test\io\fld-write.jl:65
  Test threw exception
@JeffFessler JeffFessler added the help wanted Extra attention is needed label Jul 15, 2020
@johnnychen94
Copy link
Contributor

johnnychen94 commented May 21, 2021

I'm not sure if it helps in solving this issue. But generally, it's a good practice to

  • use IOBuffer to avoid direct multiple real IO to the filesystem.
  • squash multiple println into one and avoid string interpolation. See https://docs.julialang.org/en/v1/manual/performance-tips/#Avoid-string-interpolation-for-I/O
  • not use close explicitly, and instead use the closure version of open, which automatically closes the file when it finishes or when it errors. The philosophy behind this design is RAII; let the context manager(the do-version open) manage the lifetime of the resource.
io = IOBuffer()
ndim = ndims(data)
println(io, "# AVS field file ($(basename(@__FILE__)))")
for line in head
    println(io, "# $line")
end
println(io, "ndim=$ndim")
for ii=1:ndim
    println(io, "dim$ii=$(size(data,ii))")
end
println(io,
    "nspace=", ndim, "\n",
    "veclen=1", "\n",
    "data=", datatype, "\n",
    "field=uniform", "\n")

# only write to disk once
open(file, "w") do fid
    write(fid, take!(io))
end

@JeffFessler
Copy link
Owner Author

Thanks for the tip! I've incorporated that suggestion into a PR for AVSfldIO.

BTW, I fixed the fld_write error when developing AVSfldIO by better use of temporary filenames so I can close this issue now.

@johnnychen94
Copy link
Contributor

johnnychen94 commented May 23, 2021

Clearly that you've worked this issue around.

Just FYI, I just realized that I've also met similar issues, and the workaround is to do GC.gc() before rm (I don't know why, it's perhaps related to Windows temp filesystem):

https://github.com/johnnychen94/DemoCards.jl/blob/66a7917f88813a42ce8116b93b4ee11821d4432a/src/preview.jl#L49-L54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants