Skip to content

Commit

Permalink
Fix autoreload (#5490)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored Sep 11, 2023
1 parent 3a0fa7e commit ff43d36
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion panel/io/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _exec_callback(self, post=False):
with set_curdoc(self._doc):
if self.running:
self.counter += 1
if self.counter > self.count:
if self.count is not None and self.counter > self.count:
self.stop()
cb = self.callback() if self.running else None
except Exception:
Expand Down
36 changes: 36 additions & 0 deletions panel/tests/ui/command/test_serve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import time

import pytest

from panel.tests.util import (
run_panel_serve, unix_only, wait_for_port, write_file,
)

try:
from playwright.sync_api import expect
pytestmark = pytest.mark.ui
except ImportError:
pytestmark = pytest.mark.skip('playwright not available')


@unix_only
def test_autoreload_app(py_file, port, page):
app = "import panel as pn; pn.Row('Example 1').servable()"
app2 = "import panel as pn; pn.Row('Example 2').servable()"
write_file(app, py_file.file)

app_name = os.path.basename(py_file.name)[:-3]

with run_panel_serve(["--port", str(port), '--autoreload', py_file.name]) as p:
port = wait_for_port(p.stdout)
time.sleep(0.2)

page.goto(f"http://localhost:{port}/{app_name}")
expect(page.locator(".markdown")).to_have_text("Example 1")

# Timeout to ensure websocket is initialized
time.sleep(1.0)

write_file(app2, py_file.file)
expect(page.locator(".markdown")).to_have_text('Example 2')

0 comments on commit ff43d36

Please sign in to comment.