-
-
Notifications
You must be signed in to change notification settings - Fork 517
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
Use watchfiles library for detecting changed files #5894
Conversation
This is such a nice DevEx improvement Works on Linux Jupyterhubpython==3.10 works-on-linux-jupyterhub.mp4
|
Issue: Does not pick up change in other file.If I import from another file it does not pick up the change. It only reloads. does-not-pick-up-other-change.mp4import panel as pn
import pandas as pd
import datetime as dt
from other import spacer
pn.extension("tabulator", design="material", css_files=["https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css"])
df = pd.DataFrame({
'int': [1, 2, 34],
'float': [3.14, 6.28, 9.42],
'str': ['A', 'B', 'C'],
'bool': [True, False, True],
'date': [dt.date(2019, 1, 1), dt.date(2020, 1, 1), dt.date(2020, 1, 10)],
'datetime': [dt.datetime(2019, 1, 1, 10), dt.datetime(2020, 1, 1, 12), dt.datetime(2020, 1, 10, 13)]
}, index=[1, 2, 3])
button_table = pn.widgets.Tabulator(df, buttons={
'print': '<i class="fa fa-print"></i>',
'check': '<i class="fa fa-check"></i>'
})
pn.Column(button_table, spacer).servable() import panel as pn
spacer = pn.Spacer(height=200, width=200, styles={"background": "salmon"}) |
Issue: Does not pick up change in package installed for editingMost times I'm working on a package which contains one or more apps. My package is installed with If I try this with Panel it does not seem to work. I would expect the page to reload when I hard code the Tabulator width. panel-autoreload-not-working-for-package.mp4 |
The logic was a little off, so the above issues should be fixed now. |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #5894 +/- ##
==========================================
- Coverage 84.70% 82.95% -1.76%
==========================================
Files 296 298 +2
Lines 44320 44620 +300
==========================================
- Hits 37542 37015 -527
- Misses 6778 7605 +827
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
I will be somewhat careful with adding Also, as it is a rust app, it can mean we can't support new minor versions of Python before a new app release has been compiled with the ABI. As Panel has become a dependency of many of our other packages, it will be harder to test other packages. It will also take time before it is published on the Lastly (though very minor). This adds an extra 1.2 MB, which is unnecessary for production apps in a Docker container or running an app in Pyoidide.
My points above can change depending on the other use cases. |
Good considerations @hoxbro . Maybe its worth considering whether the built in autoreload can be kept but watchfiles used if it is installed? I can see this is the approach taken by Version 0.21 supporting python 3.12 seems to have been released on pypi since october https://x.com/samuel_colvin/status/1713131500592316758?s=20 |
Thanks @hoxbro, we should definitely carefully evaluate all new dependencies. Overall none of that concerns me overly much.
For PyPI this doesn't seem a major issue,
We have control over this, we can ask for the recipe to be updated if/when we needed so this doesn't concern me very much. In fact Anaconda in general should make sure that we update Samuel's projects in a timely manner because he has a strong voice in the community. It is true that this is yet another thing for us to track though.
1.2 MB is a non-issue from my perspective. On balance I'd rather offer users a uniform experience but let's mull it over a little bit. |
Is it possible to White or blacklist dependencies for Pyodide? |
Hi, author of watchfiles here, pleased to hear you're thinking of using watchfiles. Watchfiles is on conda forge as well as anaconda proper, bit it looks like the pr for the most recent release is failing, conda-forge/watchfiles-feedstock#23 I'll try to get this merged asap. As a company we use watchfiles (via uvicorn) ever day, so we'll definitely continue to maintain the package. It's pretty stable so all it needs is updates for new versions of python. |
Thanks @samuelcolvin, really appreciate you chiming in. Really appreciate all your work. I'll start the process of getting |
Quick update here, thanks to the great conda-forge folks watchfiles 0.21 is now uploaded there and I was able to get an update on conda defaults merged as well. For now I will make watchfiles optional and issue a FutureWarning to indicate that eventually we will drop the old autoreload code and rely entirely on |
I looked a little on Github and |
bae1643
to
d92f41b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tested this PR serving (panel serve foo.py --autoreload --show
) a very simple script and after a couple of changes and saves ('test1', 'test2', 'test3', etc.), the page no longer reloads. This bug occurs with and without watchfiles
.
import panel as pn
txt = 'test1'
pn.panel(txt).servable()
Thanks @maximlt! This indeed has been a problem with autoreload since the very beginning. The issue is that autoreload relies on sending an update to the
|
pre-commit.ci autofix |
febaf23
to
a4b0dbf
Compare
a4b0dbf
to
d9b81f7
Compare
d9b81f7
to
03a9ff8
Compare
Took me weeks to figure out but I finally realized that when you shut down a server you briefly have to restart the event loop so that watchfiles can correctly catch the stop event and shut down the thread, otherwise you end up with a zombie thread. This should now finally be ready to merge. |
I noticed on windows with panel==1.3.6 the jupyter panel preview is really slow to reload. I hope this PR solves the issue. autoreload-slow-windows.mp4 |
Its actually quite slow on linux too. jupyter_panel_preview_slow_linux.mp4(I don't remember it like that ??) |
It's been relatively slow for a while. To make it robust we have to start a new kernel for each session. We might be able to look into reusing a kernel for reloads though. |
Would it be an idea to use autoreload by default but add a button to manually "restart the preview" (i.e. kernel) if something goes wrong? |
Will have to look into what's feasible, but note that this is entirely separate from "autoreload" functionality. The autoreload is triggered directly by JupyterLab file content manager events. |
Seems very likely that this is possible, could you open an issue? |
Using our own periodic callback handler sucked and turned out to be somewhat slow/unreliable. The watchfiles library on the other hand works exceptionally well, is very fast (since it is written in Rust) and simplifies our code. I think the dependency is worth it on balance, particularly since I have another usecase in mind.
@MarcSkovMadsen You may want to experiment.