Skip to content

Commit

Permalink
Ensure that autoreload records modules to watch before startup (#7399)
Browse files Browse the repository at this point in the history
* Ensure that autoreload records modules to watch before startup

* Apply suggestions from code review

* Apply suggestions from code review

* Add test

* Fix test
  • Loading branch information
philippjfr authored and ahuang11 committed Oct 18, 2024
1 parent 2986f18 commit ae110a5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
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

0 comments on commit ae110a5

Please sign in to comment.