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

Individual tracked files not revised with entr #574

Closed
c42f opened this issue Nov 18, 2020 · 1 comment · Fixed by #576
Closed

Individual tracked files not revised with entr #574

c42f opened this issue Nov 18, 2020 · 1 comment · Fixed by #576

Comments

@c42f
Copy link
Collaborator

c42f commented Nov 18, 2020

Yesterday I was trying to use Revise.entr to force live code reloading for web server development and became greatly confused because entr just seems to work inconsistently with the REPL-triggered Revise event loop.

Here's a MWE in which there's a file foo.jl containing a trivial function foo() which I'd like to revise. I expected that calling includet("foo.jl") at the top would automatically keep the function foo() up to date in the entr callback, like it does in the REPL. However

using Revise

open("foo.jl", write=true) do io
    write(io, "foo() = 0")
end

includet("foo.jl")

@sync begin
    # Simulate the user asynchronously modifying file foo 5 times
    @async for i=1:5
        sleep(1)
        open("foo.jl", write=true) do io
            write(io, "foo() = $i")
        end
    end

    entr(["foo.jl"]) do
        # I'd expect foo() to be already up to date once execution reaches this
        # point.
        @show Base.invokelatest(foo)
        # Press Ctrl-C to exit ...
    end
end

The output:

julia> include("foo_test.jl")
Base.invokelatest(foo) = 0  # should be 1
Base.invokelatest(foo) = 0  # should be 2
Base.invokelatest(foo) = 0  # etc
Base.invokelatest(foo) = 0
Base.invokelatest(foo) = 0
Base.invokelatest(foo) = 0
^C

Another thing I noticed - getting back into the REPL after running the entr() loop, the revision of foo() is now broken in the REPL as well.

@ffevotte I think this change was introduced by the callback rewrite #488 as pinning Revise to the version v2.6.7 before that was merged makes this example behave as I expect, but v2.7.0 does not.

@clarkevans this may affect you, as I was taking inspiration from your example code in JuliaWeb/HTTP.jl#587 when I hit this issue.

@c42f c42f changed the title Individual tracked files not revised with entr Individual tracked files not revised with Revise.entr Nov 18, 2020
@c42f c42f changed the title Individual tracked files not revised with Revise.entr Individual tracked files not revised with entr Nov 18, 2020
@c42f
Copy link
Collaborator Author

c42f commented Nov 18, 2020

Ok, the problem here is that add_callback() calls init_watching with no pkgdata, so the id of the files which are now watched by the callback gets set unconditionally to NOPACKAGE. In turn, this breaks revision of any of these files which were already being revised, because the id check in revise_dir_queued fails and it no longer adds them to the revision queue at:

Revise.jl/src/packagedef.jl

Lines 563 to 569 in 5c7a2c6

if id != NOPACKAGE
pkgdata = pkgdatas[id]
if hasfile(pkgdata, key) # issue #228
push!(revision_queue, (pkgdata, relpath(key, pkgdata)))
notify(revision_event)
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant