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

Ensure that autoreload records modules to watch before startup #7399

Merged
merged 5 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion panel/command/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def setup_file():
if args.warm or config.autoreload:
argvs = {f: args.args for f in files}
applications = build_single_handler_applications(files, argvs)
initialize_session = not (args.num_procs and sys.version_info < (3, 12))
initialize_session = not (args.num_procs != 1 and sys.version_info < (3, 12))
if config.autoreload:
with record_modules(list(applications.values())):
self.warm_applications(
Expand Down
26 changes: 26 additions & 0 deletions panel/tests/command/test_serve.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import re
import tempfile
import time

import pytest
import requests
Expand Down Expand Up @@ -31,6 +32,31 @@ def test_autoreload_app(py_file):
assert r2.status_code == 200
assert "<title>B</title>" in r2.content.decode('utf-8')


@linux_only
def test_autoreload_app_local_module(py_files):
py_file1, py_file2 = py_files
app_name = os.path.basename(py_file1.name)[:-3]
mod_name = os.path.basename(py_file2.name)[:-3]
app = f"import panel as pn; from {mod_name} import title; pn.Row('# Example').servable(title=title)"
write_file(app, py_file1.file)
write_file("title = 'A'", py_file2.file)

with run_panel_serve(["--port", "0", '--autoreload', py_file1.name]) as p:
port = wait_for_port(p.stdout)
r = requests.get(f"http://localhost:{port}/{app_name}")
assert r.status_code == 200
assert "<title>A</title>" in r.content.decode('utf-8')

write_file("title = 'B'", py_file2.file)
py_file2.file.close()
time.sleep(1)

r2 = requests.get(f"http://localhost:{port}/{app_name}")
assert r2.status_code == 200
assert "<title>B</title>" in r2.content.decode('utf-8')


@linux_only
def test_serve_admin(py_file):
app = "import panel as pn; pn.Row('# Example').servable(title='A')"
Expand Down
Loading