-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: on_kernel_start callbacks acculumated after hot reload
Introduced in #471 We should remove the on_kernel_start callbacks on a hot reload, but not remove the ones added by the hot reload itself.
- Loading branch information
1 parent
0c33e33
commit 33711d0
Showing
5 changed files
with
116 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import shutil | ||
from pathlib import Path | ||
|
||
import solara.server.kernel_context | ||
from solara.server import reload | ||
from solara.server.app import AppScript | ||
|
||
HERE = Path(__file__).parent | ||
|
||
kernel_start_path = HERE / "solara_test_apps" / "kernel_start.py" | ||
|
||
|
||
def test_script_reload_component(tmpdir, kernel_context, extra_include_path, no_kernel_context): | ||
|
||
target = Path(tmpdir) / "kernel_start.py" | ||
shutil.copy(kernel_start_path, target) | ||
with extra_include_path(str(tmpdir)): | ||
on_kernel_start_callbacks = solara.server.kernel_context._on_kernel_start_callbacks.copy() | ||
app = AppScript(f"{target}") | ||
try: | ||
app.run() | ||
callback = app.routes[0].module.test_callback # type: ignore | ||
assert solara.server.kernel_context._on_kernel_start_callbacks == [*on_kernel_start_callbacks, callback] | ||
prev = solara.server.kernel_context._on_kernel_start_callbacks.copy() | ||
target.touch() | ||
# wait for the event to trigger | ||
reload.reloader.reload_event_next.wait() | ||
app.run() | ||
callback = app.routes[0].module.test_callback # type: ignore | ||
assert solara.server.kernel_context._on_kernel_start_callbacks != prev | ||
assert solara.server.kernel_context._on_kernel_start_callbacks == [*on_kernel_start_callbacks, callback] | ||
finally: | ||
app.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import solara | ||
import solara.lab | ||
|
||
|
||
def test_callback(): | ||
pass | ||
|
||
|
||
solara.lab.on_kernel_start(test_callback) | ||
|
||
|
||
@solara.component | ||
def Page(): | ||
solara.Text("Hello, World!") |