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

Fix race condition in autoreload #2539

Merged
merged 2 commits into from
Jul 15, 2021
Merged

Conversation

philippjfr
Copy link
Member

When autoreload detects a modified file it clears out the sys.modules and then reloads just the session that detected the changed file. Subsequent sessions that try to detect the changed file will then no longer find the changed module in the sys.modules (meaning they can't detect a change), or they will find that the already restarted sessions has already repopulated sys.modules and delete that newly loaded module (which will potentially break the already restarted session). In the new setup whenever any session detects that a module was changed it immediately halts the watchers on other threads and then reloads all sessions.

This has the potential to fail for sessions that do not have a frontend connected (since the reload mechanism is triggered by refreshing the browser window) and those sessions will stick around. Someone could in theory reconnect to such an old session programmatically but since autoreload is meant for interactive use this does not seem like a big worry.

Fixes #2531

@codecov
Copy link

codecov bot commented Jul 15, 2021

Codecov Report

Merging #2539 (a384125) into master (4473ab2) will not change coverage.
The diff coverage is 83.33%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2539   +/-   ##
=======================================
  Coverage   83.20%   83.20%           
=======================================
  Files         184      184           
  Lines       23236    23236           
=======================================
  Hits        19334    19334           
  Misses       3902     3902           
Impacted Files Coverage Δ
panel/io/reload.py 65.90% <83.33%> (-0.76%) ⬇️
panel/pane/idom.py 27.40% <0.00%> (+0.20%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4473ab2...a384125. Read the comment docs.

@philippjfr philippjfr merged commit 2d273c7 into master Jul 15, 2021
@philippjfr philippjfr deleted the reload_race_condition_fix branch July 15, 2021 11:00
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 this pull request may close these issues.

panel serve --autoreload does not work consistently with imported modules
1 participant