Seemingly edge case of not being able to `include` while inside an `if` condition inside a loop.

bug

#1

So if I run this to re-include a file when it changes:

fname = "/full/path/to/changingfile.jl"

t1 = 0
while(true)
  if t1 != mtime(fname)
    println(isfile(fname))
    include(abspath(fname))
    t1 = mtime(fname)
  end
  Foo("a")
end

And the changingfile.jl is actually changed I get could not open file. Just wanted to know if this is normal behaviour? It does not happen when it’s inside either an if or it is just a loop.

I was impressed by Django server reloading the files I’m working on so decided to implement it in my Julia server( at least not in production ).

Thanks in advance


#2

(aside, you could do this with Revise.jl)


#3

Some editors back buffer their writes — write to a temp file, unlink the existing file inode, then rename the temp file. To avoid file corruption I think. Since you are basically polling the file constantly, if your editor does this then the file might not exist for a brief moment exactly when you are looking for it.


#4

Ah that could be it then. Thanks. I was using Neovim to edit it.


#5

Will try that out.


#6

Nope, doesn’t work.


#7

Did you do Revise.track(filename)?

Irrespective, you should still use Revise.jl for your “normal” Julia life!


#8

Yep. I use Revise mainly in the REPL and it’s a pleasure there. But no luck with this.


#9

The problem seemed to be exactly that. I put sleep(.1) and it worked. Thank you very much.