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

The auto_reload_from_file feature does not work properly in Pluto v0.17.1 #1628

Closed
holomorphism opened this issue Nov 3, 2021 · 2 comments
Closed

Comments

@holomorphism
Copy link
Contributor

In my environment, the auto_reload_from_file feature (#1029) is not working.
(When I update a file directly in the editor, the changes are not reflected in the notebook.)

I think it was working in my environment at the time of e3451b1.
My environment is as follows.

  • Pluto v0.17.1
  • Julia v1.6.1
  • Xubuntu Linux 18.04.6
  • vim 8.2

After checking the source code, it seems that there is a problem with the add() function in SessionActions.jl.

in_session() = get(session.notebooks, nb.notebook_id, nothing) === nb
session.options.server.auto_reload_from_file && @asynclog while in_session()
if !isfile(nb.path)
# notebook file deleted... let's ignore this, changing the notebook will cause it to save again. Fine for now
sleep(2)
else
watch_file(nb.path)
# the above call is blocking until the file changes
# current_time = time()
modified_time = mtime(nb.path)
# @info "File changed" (current_time - nb.last_save_time) (modified_time - nb.last_save_time) (current_time - modified_time)
if !in_session()
break
end
# if current_time - nb.last_save_time < 2.0
# @info "Notebook was saved by me very recently, not reloading from file."
if modified_time - nb.last_save_time < session.options.server.auto_reload_from_file_cooldown
# @info "Modified time is very close to my last save time, not reloading from file."
else
update_from_file_throttled()
end
end
end

in_session() = get(session.notebooks, nb.notebook_id, nothing) === nb
session.options.server.auto_reload_from_file && @asynclog while in_session()
    if !isfile(nb.path)   ### (4)
        # notebook file deleted... let's ignore this, changing the notebook will cause it to save again. Fine for now
        sleep(2)
    else
        watch_file(nb.path)   ### (1)
        # the above call is blocking until the file changes

        # current_time = time()
        modified_time = mtime(nb.path)   ### (2)
        # @info "File changed" (current_time - nb.last_save_time) (modified_time - nb.last_save_time) (current_time - modified_time)
        if !in_session()
            break
        end

        # if current_time - nb.last_save_time < 2.0
            # @info "Notebook was saved by me very recently, not reloading from file."
        if modified_time - nb.last_save_time < session.options.server.auto_reload_from_file_cooldown   ### (3)
            # @info "Modified time is very close to my last save time, not reloading from file."
        else
            update_from_file_throttled()
        end
    end
end

I inserted the @info macro and did a print debug, and found the following.
For the lines in comments (1)-(4) above,

  1. When a file is updated directly, the return value of watch_file(nb.path) (FileWatching.FileEvent) will be renamed=true instead of changed=true.
  2. Immediately after that, the value of modified_time is 0.
  3. Go to the first branch and update_from_file_throttled() will not be executed.
  4. Immediately after these, isfile(nb.path) == false.

I inserted the following lines after modified_time = mtime(nb.path), and it works fine for now.

        if modified_time == 0
            sleep(1)
            modified_time = mtime(nb.path)
        end
@fonsp
Copy link
Owner

fonsp commented Nov 3, 2021

Can you try #1584 and tell me if it worked ? #1582 was facing a similar problem

@holomorphism
Copy link
Contributor Author

Oh, I see that my issue is a complete duplicate of #1582. Sorry.
I tried #1584 and it solved the problem. Thank you very much!
I'm closing this issue.

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

No branches or pull requests

2 participants